ones with non-native dtype byteorder

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

ones with non-native dtype byteorder

Eric Firing
This (on little-endian machine) surprised me:

In [23]:np.ones((1,), dtype='<i2')
Out[23]:array([1], dtype=int16)

In [24]:np.ones((1,), dtype='>i2')
Out[24]:array([256], dtype=int16)

I expected the value to be [1] in either case. Am I wrong?  The
docstring gives no hint that this is how the dtype argument will be
interpreted.

In [27]:np.__version__
Out[27]:'1.0.5.dev4958'

Eric
_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: ones with non-native dtype byteorder

Robert Kern-2
On Mon, Apr 14, 2008 at 1:59 PM, Eric Firing <[hidden email]> wrote:
> This (on little-endian machine) surprised me:
>
>  In [23]:np.ones((1,), dtype='<i2')
>  Out[23]:array([1], dtype=int16)
>
>  In [24]:np.ones((1,), dtype='>i2')
>  Out[24]:array([256], dtype=int16)
>
>  I expected the value to be [1] in either case. Am I wrong?

You are correct. It is a bug in the @NAME@_fillwithscalar() template
in arraytypes.inc.src; it does not take endianness into consideration.
I mentioned this to Travis, and he might have time to hop on this, but
if anyone else can fix it faster, please go for it.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
 -- Umberto Eco
_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: ones with non-native dtype byteorder

Travis Oliphant-5
Robert Kern wrote:

> On Mon, Apr 14, 2008 at 1:59 PM, Eric Firing <[hidden email]> wrote:
>  
>> This (on little-endian machine) surprised me:
>>
>>  In [23]:np.ones((1,), dtype='<i2')
>>  Out[23]:array([1], dtype=int16)
>>
>>  In [24]:np.ones((1,), dtype='>i2')
>>  Out[24]:array([256], dtype=int16)
>>
>>  I expected the value to be [1] in either case. Am I wrong?
>>    
>
> You are correct. It is a bug in the @NAME@_fillwithscalar() template
> in arraytypes.inc.src; it does not take endianness into consideration.
> I mentioned this to Travis, and he might have time to hop on this, but
> if anyone else can fix it faster, please go for it.
>
>  
Could you check latest SVN.    This should be fixed now.

-Travis O.



_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: ones with non-native dtype byteorder

Eric Firing
Travis E. Oliphant wrote:

> Robert Kern wrote:
>> On Mon, Apr 14, 2008 at 1:59 PM, Eric Firing <[hidden email]> wrote:
>>  
>>> This (on little-endian machine) surprised me:
>>>
>>>  In [23]:np.ones((1,), dtype='<i2')
>>>  Out[23]:array([1], dtype=int16)
>>>
>>>  In [24]:np.ones((1,), dtype='>i2')
>>>  Out[24]:array([256], dtype=int16)
>>>
>>>  I expected the value to be [1] in either case. Am I wrong?
>>>    
>> You are correct. It is a bug in the @NAME@_fillwithscalar() template
>> in arraytypes.inc.src; it does not take endianness into consideration.
>> I mentioned this to Travis, and he might have time to hop on this, but
>> if anyone else can fix it faster, please go for it.
>>
>>  
> Could you check latest SVN.    This should be fixed now.

Indeed it is.  Thank you.

Eric
>
> -Travis O.
>
>
>
> _______________________________________________
> Numpy-discussion mailing list
> [hidden email]
> http://projects.scipy.org/mailman/listinfo/numpy-discussion

_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion