[Numpy-discussion] numpy type mismatch

Mark Wiebe mwwiebe at gmail.com
Sat Jun 11 00:00:55 EDT 2011


On Fri, Jun 10, 2011 at 9:55 PM, Benjamin Root <ben.root at ou.edu> wrote:

>
>
> On Fri, Jun 10, 2011 at 8:51 PM, Keith Goodman <kwgoodman at gmail.com>wrote:
>
>> On Fri, Jun 10, 2011 at 6:35 PM, Charles R Harris
>> <charlesr.harris at gmail.com> wrote:
>> > On Fri, Jun 10, 2011 at 5:19 PM, Olivier Delalleau <shish at keba.be>
>> wrote:
>>
>> >> But isn't it a bug if numpy.dtype('i') != numpy.dtype('l') on a 32 bit
>> >> computer where both are int32?
>> >>
>> >
>> > Maybe yes, maybe no ;) They have different descriptors, so from numpy's
>> > perspective they are different, but at the hardware/precision level they
>> are
>> > the same. It's more of a decision as to what  != means in this case.
>> Since
>> > numpy started as Numeric with only the c types the current behavior is
>> > consistent, but that doesn't mean it shouldn't change at some point.
>>
>> Maybe this is the same question, but are you maybe yes, maybe no on this
>> too:
>>
>>    >>> type(np.sum([1, 2, 3], dtype=np.int32)) == np.int32
>>    False
>>
>> Ben, what happens if you put an axis in there? Like
>>
>>    >>> np.sum([[1, 2, 3], [4,5,6]], axis=0).dtype == np.int32
>>
>
> The same thing happens as before.
>
>
>>
>> Just wondering if this is another different-dtype-for-different-axis case.
>>
>
> No, I think Chuck has it right and that this is the result of the recent
> cleanup work for ufunc casting rules.  However, I am so entirely unfamiliar
> with ufuncs that I really don't know how to investigate this.  Can we get
> Mark Wiebe's opinion on this?  I suspect he might recognize the problem
> right away.
>

Yeah, it's basically a misfeature of NumPy which is apparently inherited
from Numeric. The type resolution changes to 1.6 changed where this would
pop up, but it's always been there in the code. I suspect that eliminating
the long type, and making it an alias to either int or longlong depending on
the platform, would fix all of this on all current platforms.

Cheers,
Mark


>
> Ben Root
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110610/9a6f84ca/attachment.html>


More information about the NumPy-Discussion mailing list