[NumPy-Tickets] [NumPy] #1490: searchsorted does not work properly for non-native endianness

NumPy Trac numpy-tickets@scipy....
Tue May 25 22:36:04 CDT 2010


#1490: searchsorted does not work properly for non-native endianness
------------------------+---------------------------------------------------
 Reporter:  briangerke  |       Owner:  somebody
     Type:  defect      |      Status:  new     
 Priority:  normal      |   Milestone:  2.0.0   
Component:  Other       |     Version:          
 Keywords:              |  
------------------------+---------------------------------------------------
 I am currently using numpy version '1.4.1rc2'.  I have encountered this in
 several other versions, however.

 The searchsorted function sometimes gives incorrect results when it is
 passed two arrays that are both in non-native endianness.  The following
 is copied from an email I sent to another numpy user, to make sure I
 wasn't going crazy.  He confirmed the bug.


 > Consider this (running interactively in ipython on my little-endian
 Intel MacBook):

 >
 > In [5]: searchsorted(arange(900, dtype='i4'), array([894,895],
 dtype='i4'))

 >
 > Out[5]: array([894, 895])

 >
 > That's working as it should: searchsorted just says to insert 894 and
 895

 > before elements 894 and 895 in a range array that runs from 0 to 899.

 >

 > But now if I turn both input arrays into big-endian, things get weird:
 >

 > In [6]: searchsorted(arange(900, dtype='>i4'), array([894,895],
 > dtype='>i4'))
 >

 > Out[6]: array([894, 900])
 >

 > Now searchsorted says to insert 894 before the 894th element (correct)
 but
 > that 895 is bigger than 899 and should thus be inserted at the end
 (what?).
 >

 > Similar nonsense occurs if I use big-endian floats:
 >

 > In [13]: searchsorted(arange(900, dtype='>f4'), array([894,895],
 > dtype='>f4'))
 >

 > Out[13]: array([679, 899])
 >

 > Now it says that 894<679 and 895=899.  Huh?
 >

 > As far as I can tell, this only occurs when BOTH arrays are explicitly
 > big-endian:
 >

 > In [7]: searchsorted(arange(900, dtype='>i4'), array([894,895],
 dtype='i4'))
 >

 > Out[7]: array([894, 895])
 >

 > In [8]: searchsorted(arange(900, dtype='i4'), array([894,895],
 dtype='>i4'))
 >

 > Out[8]: array([894, 895])
 >

 > Apparently if EITHER input array has native endian-ness, there is no
 > problem.

 I would be surprised to discover that this is expected behavior.  Surely
 the endianness ought not to matter.

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/1490>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list