-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
Recall the signature of numpy.full_like:
numpy.full_like(a, fill_value,...)On the other hand, physipy uses the __array_function__ interface to overload numpy calls on quantity-arrays. This works well for the following cases:
import numpy
from physipy import m, rad
assert (np.full_like(np.arange(10)*m, 3) == np.full(10, 3)).all()
assert (np.full_like(np.arange(10)*m, 3*m) == np.full(10, 3)*m).all()
assert (np.full_like(np.arange(10)*m, 3*rad) == np.full(10, 3)*rad).all()But in the case where only the fill_value is a quantity, the __array__function__ interface is not triggered, so the following relies on numpy's full_like, which is basically:
res = empty_like(
a, dtype=dtype, order=order, subok=subok, shape=shape, device=device
)
multiarray.copyto(res, fill_value, casting='unsafe')
return ressince a is a regular array, empty_like also returns a regular array. But then copyto triggers the __array_interface__ and delegates to physipy's implementation, which checks for dimension equality.
Overall :
>>> np.full_like(np.arange(10), 3*m)
...
DimensionError: Dimension error : dimensions of operands are no-dimension and L, and are differents (dimensionless vs length).raises a DimensionError.
Which raises 2 questions:
- why does
multiarray.copyto(np_array, quantity)triggers the__array_interface__but notnp.full_like(np_array, quantity)? - should
physipy's implementation ofnp.copytoenforce dimension equality ?
Similar issue with np.full :
Metadata
Metadata
Assignees
Labels
No labels