@@ -39,76 +39,6 @@ Special attributes and methods
3939
4040Numpy provides several hooks that classes can customize:
4141
42- .. function :: class.__numpy_ufunc__(self, ufunc, method, i, inputs, **kwargs)
43-
44- .. versionadded :: 1.9
45-
46- Any class (ndarray subclass or not) can define this method to
47- override behavior of Numpy's ufuncs. This works quite similarly to
48- Python's ``__mul__ `` and other binary operation routines.
49-
50- - *ufunc * is the ufunc object that was called.
51- - *method * is a string indicating which Ufunc method was called
52- (one of ``"__call__" ``, ``"reduce" ``, ``"reduceat" ``,
53- ``"accumulate" ``, ``"outer" ``, ``"inner" ``).
54- - *i * is the index of *self * in *inputs *.
55- - *inputs * is a tuple of the input arguments to the ``ufunc ``
56- - *kwargs * is a dictionary containing the optional input arguments
57- of the ufunc. The ``out `` argument is always contained in
58- *kwargs *, if given. See the discussion in :ref: `ufuncs ` for
59- details.
60-
61- The method should return either the result of the operation, or
62- :obj: `NotImplemented ` if the operation requested is not
63- implemented.
64-
65- If one of the arguments has a :func: `__numpy_ufunc__ ` method, it is
66- executed *instead * of the ufunc. If more than one of the input
67- arguments implements :func: `__numpy_ufunc__ `, they are tried in the
68- order: subclasses before superclasses, otherwise left to right. The
69- first routine returning something else than :obj: `NotImplemented `
70- determines the result. If all of the :func: `__numpy_ufunc__ `
71- operations return :obj: `NotImplemented `, a :exc: `TypeError ` is
72- raised.
73-
74- If an :class: `ndarray ` subclass defines the :func: `__numpy_ufunc__ `
75- method, this disables the :func: `__array_wrap__ `,
76- :func: `__array_prepare__ `, :data: `__array_priority__ ` mechanism
77- described below.
78-
79- .. note :: In addition to ufuncs, :func:`__numpy_ufunc__` also
80- overrides the behavior of :func: `numpy.dot ` even though it is
81- not an Ufunc.
82-
83- .. note :: If you also define right-hand binary operator override
84- methods (such as ``__rmul__ ``) or comparison operations (such as
85- ``__gt__ ``) in your class, they take precedence over the
86- :func: `__numpy_ufunc__ ` mechanism when resolving results of
87- binary operations (such as ``ndarray_obj * your_obj ``).
88-
89- The technical special case is: ``ndarray.__mul__ `` returns
90- ``NotImplemented `` if the other object is *not * a subclass of
91- :class: `ndarray `, and defines both ``__numpy_ufunc__ `` and
92- ``__rmul__ ``. Similar exception applies for the other operations
93- than multiplication.
94-
95- In such a case, when computing a binary operation such as
96- ``ndarray_obj * your_obj ``, your ``__numpy_ufunc__ `` method
97- *will not * be called. Instead, the execution passes on to your
98- right-hand ``__rmul__ `` operation, as per standard Python
99- operator override rules.
100-
101- Similar special case applies to *in-place operations *: If you
102- define ``__rmul__ ``, then ``ndarray_obj *= your_obj `` *will not *
103- call your ``__numpy_ufunc__ `` implementation. Instead, the
104- default Python behavior ``ndarray_obj = ndarray_obj * your_obj ``
105- occurs.
106-
107- Note that the above discussion applies only to Python's builtin
108- binary operation mechanism. ``np.multiply(ndarray_obj,
109- your_obj) `` always calls only your ``__numpy_ufunc__ ``, as
110- expected.
111-
11242.. function :: class.__array_finalize__(self)
11343
11444 This method is called whenever the system internally allocates a
0 commit comments