[Numpy-discussion] numarray bug: dot product between 2x2 and 3x2x3 on Mac different from PC
oliphant.travis at ieee.org
Mon Jul 17 14:38:29 CDT 2006
Sebastian Haase wrote:
> On Monday 17 July 2006 12:10, Travis Oliphant wrote:
>> Sebastian Haase wrote:
>>> Traceback (most recent call last):
>>> File "<input>", line 1, in ?
>>> TypeError: array cannot be safely cast to required type
>>> [[[ 1. 1. 1.]
>>> [ 1. 1. 1.]
>>> [ 1. 1. 1.]]
>>> [[ 2. 2. 2.]
>>> [ 2. 2. 2.]
>>> [ 2. 2. 2.]]]
>>> The TypeError looks like a numpy bug !
>> I don't see why this is a bug. You are trying to coerce a 32-bit
>> integer to a 32-bit float. That is going to lose precision and so you
>> get the error indicated.
> In numarray I do not get an error. Would the error go away if I had 64 bit
> float !? It seems though that having ones and twos in an int array should
> fit just fine into a float32 array !?
This could be considered a bug in numarray. It's force-casting the
result. That isn't the normal behavior of mixed-type functions.
Also, the policy on type-casting is not to search the array to see if
it's possible to do the conversion on every element (that would be slow
on large arrays). The policy is to base the decision only on the
data-types themselves (i.e. whether it's *possible* to lose precision*).
*There is one exception to this policy in NumPy: 64-bit integers are
allowed to be cast to 64-bit doubles --- other-wise on you would get a
lot of non-standard long-doubles showing up on 64-bit systems. This
policy was decided after discussion last year.
More information about the Numpy-discussion