diff options
| author | Ryan Soklaski <ryan.soklaski@gmail.com> | 2021-01-26 21:04:10 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-26 21:04:10 -0500 |
| commit | 78dd98729ab455c89c8ec50da90da4d35a6c4a48 (patch) | |
| tree | 9f1e45a763650633af262c52aae4dd9822239e33 /doc | |
| parent | fd996225c5f712e7fc4e301c6e698a8a10854dd9 (diff) | |
| download | numpy-78dd98729ab455c89c8ec50da90da4d35a6c4a48.tar.gz | |
DOC: __array__ accepts a dtype argument
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/source/user/basics.dispatch.rst | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/doc/source/user/basics.dispatch.rst b/doc/source/user/basics.dispatch.rst index 147f86c98..089a7df17 100644 --- a/doc/source/user/basics.dispatch.rst +++ b/doc/source/user/basics.dispatch.rst @@ -22,8 +22,8 @@ example that has rather narrow utility but illustrates the concepts involved. ... self._i = value ... def __repr__(self): ... return f"{self.__class__.__name__}(N={self._N}, value={self._i})" -... def __array__(self): -... return self._i * np.eye(self._N) +... def __array__(self, dtype=None): +... return self._i * np.eye(self._N, dtype=dtype) Our custom array can be instantiated like: @@ -84,8 +84,8 @@ For this example we will only handle the method ``__call__`` ... self._i = value ... def __repr__(self): ... return f"{self.__class__.__name__}(N={self._N}, value={self._i})" -... def __array__(self): -... return self._i * np.eye(self._N) +... def __array__(self, dtype=None): +... return self._i * np.eye(self._N, dtype=dtype) ... def __array_ufunc__(self, ufunc, method, *inputs, **kwargs): ... if method == '__call__': ... N = None @@ -133,8 +133,8 @@ conveniently by inheriting from the mixin ... self._i = value ... def __repr__(self): ... return f"{self.__class__.__name__}(N={self._N}, value={self._i})" -... def __array__(self): -... return self._i * np.eye(self._N) +... def __array__(self, dtype=None): +... return self._i * np.eye(self._N, dtype=dtype) ... def __array_ufunc__(self, ufunc, method, *inputs, **kwargs): ... if method == '__call__': ... N = None @@ -171,8 +171,8 @@ functions to our custom variants. ... self._i = value ... def __repr__(self): ... return f"{self.__class__.__name__}(N={self._N}, value={self._i})" -... def __array__(self): -... return self._i * np.eye(self._N) +... def __array__(self, dtype=None): +... return self._i * np.eye(self._N, dtype=dtype) ... def __array_ufunc__(self, ufunc, method, *inputs, **kwargs): ... if method == '__call__': ... N = None |
