Re: [Numpy-discussion] Questions about the array interface.
--- Andrew Straw <strawman@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. Cheers, -Scott
Scott Gilbert wrote:
--- Andrew Straw <strawman@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 -- Robert Kern rkern@ucsd.edu "In the fields of hell where the grass grows high Are the graves of dreams allowed to die." -- Richard Harter
Robert Kern wrote:
Scott Gilbert wrote:
--- Andrew Straw <strawman@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.
participants (3)
-
Andrew Straw -
Robert Kern -
Scott Gilbert