Marten van Kerkwijk
2016-01-06 22:17:35 UTC
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
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