diff options
author | Stephan Hoyer <shoyer@google.com> | 2017-04-29 21:19:21 -0700 |
---|---|---|
committer | Stephan Hoyer <shoyer@google.com> | 2017-04-30 14:22:09 -0700 |
commit | 777534d5a6b2a8850dd8a6c52c17f94145f0ef03 (patch) | |
tree | 198b11366eb4b8c18a6146437866ed59d3102811 /doc/source/reference | |
parent | b0825b438237ee6eb7f1340e5615e036267f7a05 (diff) | |
download | numpy-777534d5a6b2a8850dd8a6c52c17f94145f0ef03.tar.gz |
DOC: update docs for __array_ufunc__ = None
Diffstat (limited to 'doc/source/reference')
-rw-r--r-- | doc/source/reference/arrays.classes.rst | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/doc/source/reference/arrays.classes.rst b/doc/source/reference/arrays.classes.rst index 25105001c..2719f9239 100644 --- a/doc/source/reference/arrays.classes.rst +++ b/doc/source/reference/arrays.classes.rst @@ -81,14 +81,11 @@ NumPy provides several hooks that classes can customize: same may happen with functions such as :func:`~numpy.median`, :func:`~numpy.min`, and :func:`~numpy.argsort`. - Like with some other special methods in python, such as ``__hash__`` and ``__iter__``, it is possible to indicate that your class does *not* - support ufuncs by setting ``__array_ufunc__ = None``. With this, - inside ufuncs, your class will be treated as if it returned - :obj:`NotImplemented` (which will lead to an :exc:`TypeError` - unless another class also provides a :func:`__array_ufunc__` method - which knows what to do with your class). + support ufuncs by setting ``__array_ufunc__ = None``. Ufuncs always raise + :exc:`TypeError` when called on an object that sets + ``__array_ufunc__ = None``. The presence of :func:`__array_ufunc__` also influences how :class:`ndarray` handles binary operations like ``arr + obj`` and ``arr @@ -102,10 +99,9 @@ NumPy provides several hooks that classes can customize: Alternatively, if ``obj.__array_ufunc__`` is set to :obj:`None`, then as a special case, special methods like ``ndarray.__add__`` will notice this - and *unconditionally* return :obj:`NotImplemented`, so that Python will - dispatch to ``obj.__radd__`` instead. This is useful if you want to define - a special object that interacts with arrays via binary operations, but - is not itself an array. For example, a units handling system might have + and *unconditionally* raise :exc:`TypeError`. This is useful if you want to + create objects that interact with arrays via binary operations, but + are not themselves arrays. For example, a units handling system might have an object ``m`` representing the "meters" unit, and want to support the syntax ``arr * m`` to represent that the array has units of "meters", but not want to otherwise interact with arrays via ufuncs or otherwise. This |