[Numpy-tickets] [NumPy] #826: Error in basic arithmetic involving masked objects and scalar types
NumPy
numpy-tickets@scipy....
Wed Jan 21 12:23:10 CST 2009
#826: Error in basic arithmetic involving masked objects and scalar types
------------------------+---------------------------------------------------
Reporter: dharland | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone: 1.3.0
Component: numpy.core | Version: none
Severity: major | Resolution:
Keywords: ma |
------------------------+---------------------------------------------------
Comment (by DarrenDale):
This issue is causing problems for me as well. Here is a script
illustrating the problem:
{{{
import numpy as np
class MyArray(np.ndarray):
__array_priority__ = 20
def __new__(cls):
return np.asarray(1.0, 'float64').view(cls).copy()
def __repr__(self):
return 'my_array'
__str__ = __repr__
def __mul__(self, other):
return super(MyArray, self).__mul__(other)
def __rmul__(self, other):
return super(MyArray, self).__rmul__(other)
mine = MyArray()
print type(np.float32(1)*mine)
print type(mine*np.float32(1))
print type(mine*np.float64(1))
print type(1*mine)
print type(mine*1)
print type(np.float64(1)*mine)
}}}
the first 5 print statements yield a !MyArray, the final one yields a
numpy.float64. If I initialize my subclass to have a dtype of float128,
the final test yields a !MyArray again.
I can understand the need to cast the !MyArray instance to the higher
dtype, but I dont understand why that has any bearing on the results type,
which should respect `__array_priority__` if I understand
`__array_priority__`'s purpose correctly.
--
Ticket URL: <http://scipy.org/scipy/numpy/ticket/826#comment:5>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.
More information about the Numpy-tickets
mailing list