[Numpy-discussion] Questions about the array interface.

Andrew Straw strawman at astraw.com
Fri Apr 8 08:00:13 CDT 2005


Robert Kern wrote:

> Scott Gilbert wrote:
>
>> --- Andrew Straw <strawman at astraw.com> wrote:
>>
>>> Here's a bit of weirdness which has prevented me from using '<' or 
>>> '>' in the past with the struct module.  I'm not guru enough to know 
>>> what's going on, but it has prevented me from being explicit rather 
>>> than
>>> implicit.
>>>
>>> In [1]:import struct
>>>
>>> In [2]:from numarray.ieeespecial import nan
>>>
>>> In [3]:nan
>>> Out[3]:nan
>>>
>>> In [4]:struct.pack('<d',nan)
>>>
>>
>> --------------------------------------------------------------------------- 
>>
>>
>>> exceptions.SystemError                               Traceback (most 
>>> recent call last)
>>>
>>> /home/astraw/<console>
>>>
>>> SystemError: frexp() result out of range
>>>
>>> In [5]:struct.pack('d',nan)
>>> Out[5]:'\x00\x00\x00\x00\x00\x00\xf8\xff'
>>>
>>
>>
>>
>> No clue why that is, but it certainly looks like a bug in the struct
>> module.  It shouldn't make any difference about whether or not the array
>> protocol reports the endian though.  It's using a different notation for
>> typecodes.
>
>
> This behavior is expplained by Tim Peters:
>
> http://groups-beta.google.com/group/comp.lang.python/msg/16dbf848c050405a
>
I feared it was something like that. (No platform independent way to 
represent special values like nan, inf, and so on.)  So I think if we're 
going to require an encoding character such as '<' or '>' we should also 
include one that means native which CAN handle these special values... 
And document why it's needed and why it may get one into trouble.





More information about the Numpy-discussion mailing list