-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
ENH: Add __array_ufunc__
#8247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH: Add __array_ufunc__
#8247
Changes from 1 commit
4fd7e84
fcd11d2
c7b25e2
8a9e790
4dd5380
7d9bc2f
e4b5163
2e6d8c0
d5c5ac1
3124e96
6a3ca31
79bb733
7c3dc5a
71201d2
3041710
5fe6fc6
e092823
1147894
e325a10
39c2273
6b41d11
0ede0e9
5f9252c
8cc2f71
856da73
2b6c7fd
36e8494
55500b9
25e973d
b1fa10a
1de8f5a
a460015
cd2e42c
ff628f1
1fc6e63
a431743
1e460b7
02600d3
d3ff023
b9359f1
256a8ae
3272a86
32221df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,13 +39,13 @@ Special attributes and methods | |
|
||
NumPy provides several hooks that classes can customize: | ||
|
||
.. method:: class.__array_ufunc__(ufunc, method, *inputs, **kwargs) | ||
.. py:method:: class.__array_ufunc__(ufunc, method, *inputs, **kwargs) | ||
|
||
.. versionadded:: 1.13 | ||
|
||
Any class (ndarray subclass or not) can define this method (or set it to | ||
:obj:`None`) to override behavior of NumPy's ufuncs. This works quite | ||
similarly to Python's ``__mul__`` and other binary operation routines. | ||
Any class, ndarray subclass or not, can define this method or set it to | ||
:obj:`None` in order to override the behavior of NumPy's ufuncs. This works | ||
quite similarly to Python's ``__mul__`` and other binary operation routines. | ||
|
||
- *ufunc* is the ufunc object that was called. | ||
- *method* is a string indicating which Ufunc method was called | ||
|
@@ -94,17 +94,17 @@ NumPy provides several hooks that classes can customize: | |
|
||
.. note:: If you subclass :class:`ndarray`, we strongly recommend | ||
that you avoid confusion by neither setting | ||
:func:`__array_ufunc__` to :obj:`None` (which seems to make no | ||
sense for an array subclass), nor defining it and also defining | ||
reverse methods (which will be called by ``CPython`` in | ||
preference over the :class:`ndarray` forward methods). | ||
:func:`__array_ufunc__` to :obj:`None`, which makes no | ||
sense for an array subclass, nor by defining it and also defining | ||
reverse methods, which methods will be called by ``CPython`` in | ||
preference over the :class:`ndarray` forward methods. | ||
|
||
.. note:: If a class defines the :func:`__array_ufunc__` method, | ||
this disables the :func:`__array_wrap__`, | ||
:func:`__array_prepare__`, :data:`__array_priority__` mechanism | ||
described below (which may eventually be deprecated). | ||
|
||
.. method:: class.__array_finalize__(obj) | ||
.. py:method:: class.__array_finalize__(obj) | ||
|
||
This method is called whenever the system internally allocates a | ||
new array from *obj*, where *obj* is a subclass (subtype) of the | ||
|
@@ -113,7 +113,7 @@ NumPy provides several hooks that classes can customize: | |
to update meta-information from the "parent." Subclasses inherit | ||
a default implementation of this method that does nothing. | ||
|
||
.. method:: class.__array_prepare__(array, context=None) | ||
.. py:method:: class.__array_prepare__(array, context=None) | ||
|
||
At the beginning of every :ref:`ufunc <ufuncs.output-type>`, this | ||
method is called on the input object with the highest array | ||
|
@@ -126,9 +126,9 @@ NumPy provides several hooks that classes can customize: | |
ufunc for computation. | ||
|
||
.. note:: It is hoped to eventually deprecate this method in favour of | ||
:func:__array_ufunc__`. | ||
:func:`__array_ufunc__`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this note apply to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not until we have found a way to substitute the use of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But we use |
||
|
||
.. method:: class.__array_wrap__(array, context=None) | ||
.. py:method:: class.__array_wrap__(array, context=None) | ||
|
||
At the end of every :ref:`ufunc <ufuncs.output-type>`, this method | ||
is called on the input object with the highest array priority, or | ||
|
@@ -140,17 +140,17 @@ NumPy provides several hooks that classes can customize: | |
into an instance of the subclass and update metadata before | ||
returning the array to the user. | ||
|
||
.. data:: class.__array_priority__ | ||
.. py:attribute:: class.__array_priority__ | ||
|
||
The value of this attribute is used to determine what type of | ||
object to return in situations where there is more than one | ||
possibility for the Python type of the returned object. Subclasses | ||
inherit a default value of 0.0 for this attribute. | ||
|
||
.. note:: It is hoped to eventually deprecate this attribute in favour | ||
of :func:__array_ufunc__`. | ||
of :func:`__array_ufunc__`. | ||
|
||
.. method:: class.__array__([dtype]) | ||
.. py:method:: class.__array__([dtype]) | ||
|
||
If a class (ndarray subclass or not) having the :func:`__array__` | ||
method is used as the output object of an :ref:`ufunc | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unlikely to be true, given that a bunch of non-ufuncs invoke (parts of) this interface. Perhaps clarify to "this disables the ... interface for ufuncs"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in charris#5