[Numpy-discussion] Subclass awareness of outer, inner, dot, ...

Marten van Kerkwijk m.h.vankerkwijk at gmail.com
Wed Jan 6 17:17:35 EST 2016


Hi All,

Having just had a look at functions where astropy's quantities are silently
converted to ndarray, I came across some that, in principle, are easy to
solve, yet for which, as always, there is a worry about backward
compatibility. So, the question arises what to do.

As a specific example, consider `np.outer` which is defined in `numeric.py`
and boils down to

multiply(a.ravel()[:, newaxis], b.ravel()[newaxis,:], out)

Since multiply is fine with subclasses, all should be well, except that
before it is called, there are `a = asarray(a)` and `b = asarray(b)`
statements, which mean subclasses are lost.

Obviously, in this case, a simple fix would be to use `asanyarray` instead,
but ideally, similar routines behave similarly and hence one would also
want to change `np.inner` and `np.dot` (and perhaps more)... Hence, before
doing anything, I thought I would ask whether:

1. Such changes are or are not too risky for backward compatibility;
2. If so, whether, given that `np.dot` can be caught using
`__numpy_ufunc__`, one should perhaps allow functions such as `outer` also
to be passed through that?

All the best,

Marten
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20160106/effb2743/attachment.html>


More information about the NumPy-Discussion mailing list