summaryrefslogtreecommitdiff
path: root/doc/source/reference/ufuncs.rst
diff options
context:
space:
mode:
authorDarren Dale <dsdale24@gmail.com>2009-08-23 16:30:28 +0000
committerDarren Dale <dsdale24@gmail.com>2009-08-23 16:30:28 +0000
commit9e053da77d773fb22ee83219ad5595af6c73c953 (patch)
tree955f7f9eae0d972c8d12019b5b873811de136505 /doc/source/reference/ufuncs.rst
parent856a9363bf28da036c6102fc77ea7fcdba5e777a (diff)
downloadnumpy-9e053da77d773fb22ee83219ad5595af6c73c953.tar.gz
add support for __array_prepare__
Diffstat (limited to 'doc/source/reference/ufuncs.rst')
-rw-r--r--doc/source/reference/ufuncs.rst21
1 files changed, 13 insertions, 8 deletions
diff --git a/doc/source/reference/ufuncs.rst b/doc/source/reference/ufuncs.rst
index 09b13dc89..8096e1497 100644
--- a/doc/source/reference/ufuncs.rst
+++ b/doc/source/reference/ufuncs.rst
@@ -102,19 +102,24 @@ Output type determination
The output of the ufunc (and its methods) is not necessarily an
:class:`ndarray`, if all input arguments are not :class:`ndarrays <ndarray>`.
-All output arrays will be passed to the :obj:`__array_wrap__`
-method of the input (besides :class:`ndarrays <ndarray>`, and scalars)
-that defines it **and** has the highest :obj:`__array_priority__` of
-any other input to the universal function. The default
-:obj:`__array_priority__` of the ndarray is 0.0, and the default
-:obj:`__array_priority__` of a subtype is 1.0. Matrices have
-:obj:`__array_priority__` equal to 10.0.
+All output arrays will be passed to the :obj:`__array_prepare__` and
+:obj:`__array_wrap__` methods of the input (besides
+:class:`ndarrays <ndarray>`, and scalars) that defines it **and** has
+the highest :obj:`__array_priority__` of any other input to the
+universal function. The default :obj:`__array_priority__` of the
+ndarray is 0.0, and the default :obj:`__array_priority__` of a subtype
+is 1.0. Matrices have :obj:`__array_priority__` equal to 10.0.
The ufuncs can also all take output arguments. The output will be cast
if necessary to the provided output array. If a class with an
:obj:`__array__` method is used for the output, results will be
written to the object returned by :obj:`__array__`. Then, if the class
-also has an :obj:`__array_wrap__` method, the returned
+also has an :obj:`__array_prepare__` method, it is called so metadata
+may be determined based on the context of the ufunc (the context
+consisting of the ufunc itself, the arguments passed to the ufunc, and
+the ufunc domain.) The array object returned by
+:obj:`__array_prepare__` is passed to the ufunc for computation.
+Finally, if the class also has an :obj:`__array_wrap__` method, the returned
:class:`ndarray` result will be passed to that method just before
passing control back to the caller.