[Numpy-discussion] Re: weird interaction: pickle, numpy, matplotlib.hist

Travis Oliphant oliphant.travis at ieee.org
Thu Apr 6 02:46:02 CDT 2006


Robert Kern wrote:
> You have a byteorder issue. You Linux box, which I presume has an Intel or AMD
> CPU, is little-endian where your OS X box, which I presume has a PPC CPU, is
> big-endian. numpy arrays can store their data in either endianness on either
> kind of platform; their dtype objects tell you which byteorder they are using.
>
> In [54]: c.sort()
>
> In [55]: c
> Out[55]: array([  0.,   2.,   3.,   4.,   5.,   6.,   7.,   8.,   9.,  10.,   1.])
>
>
> This is a bug.
>
> http://projects.scipy.org/scipy/numpy/ticket/47
>   
Good catch.  This bug was due to an oversight when adding the new 
sorting functions.  The case of byte-swapped data was not handled.   
Judicious use of copyswap on the buffer fixed it.

But,  this brings up the point that currently the pickled raw-data which 
is read-in as a string by Python is used as the memory for the new array 
(i.e. the string memory is "stolen").    This should work.  The fact 
that it didn't with sort was a bug that is now fixed in SVN.  However, 
operations on out-of-byte-order arrays will always be slower.  Thus, 
perhaps on pickle read the data should be copied to native byte-order if 
necessary.

Opinions?

-Travis









More information about the Numpy-discussion mailing list