[NumPy-Tickets] [NumPy] #2144: .max(0) on reshaped array returns inconsistent results.

NumPy Trac numpy-tickets@scipy....
Fri May 25 19:06:44 CDT 2012


#2144: .max(0) on reshaped array returns inconsistent results.
--------------------+-------------------------------------------------------
 Reporter:  thouis  |       Owner:  somebody   
     Type:  defect  |      Status:  new        
 Priority:  normal  |   Milestone:  Unscheduled
Component:  Other   |     Version:  devel      
 Keywords:          |  
--------------------+-------------------------------------------------------

Comment(by thouis):

 I think I've traced it down to this line being executed at the last loop
 of the iteration it's controlling:

 https://github.com/numpy/numpy/commit/aed9925a9d5fe9a407d0ca2c65cb577116c4d0f1#L11R2896
 {{{
 while (iternext(iter));
 }}}

 Before this line executes, the data is correct.  Afterward, it has been
 scribbled over with something that looks suspiciously like a pointer's
 value.

 The call to iternext at the end of the loop calls this:
 https://github.com/numpy/numpy/blob/aed9925a9d5fe9a407d0ca2c65cb577116c4d0f1/numpy/core/src/multiarray/nditer_templ.c.src#L252
 {{{
 npyiter_copy_from_buffers(iter);
 }}}

 Which *only when it crashes*, goes into this piece of code:
 https://github.com/numpy/numpy/blob/aed9925a9d5fe9a407d0ca2c65cb577116c4d0f1/numpy/core/src/multiarray/nditer_api.c#L1878

 and executes this:
 https://github.com/numpy/numpy/blob/aed9925a9d5fe9a407d0ca2c65cb577116c4d0f1/numpy/core/src/multiarray/nditer_api.c#L1997

 I'm reasonably certain it shouldn't be going into the if clause based on
 delta at line 1878, but I haven't unraveled enough of that code to know
 for sure.

 However, changing the second <= to < at this line (since it looks like an
 off-by-one error, and every time it crashed, it was under the == case of
 <=):
 https://github.com/numpy/numpy/blob/aed9925a9d5fe9a407d0ca2c65cb577116c4d0f1/numpy/core/src/multiarray/nditer_api.c#L1872

 seems to fix the crash.  Mark, can you verify that my intuition about this
 comparison is correct?

 All tests pass with this change, except one:
 {{{
 FAIL: test_where_param_buffer_output (test_ufunc.TestUfunc)
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File "/Users/tjones/numpy.git/numpy/core/tests/test_ufunc.py", line 598,
 in test_where_param_buffer_output
     assert_equal(c, [2,1.5,1.5,2,1.5,1.5,2,2,2,1.5])
   File "/Users/tjones/numpy.git/numpy/testing/utils.py", line 256, in
 assert_equal
     return assert_array_equal(actual, desired, err_msg, verbose)
   File "/Users/tjones/numpy.git/numpy/testing/utils.py", line 753, in
 assert_array_equal
     verbose=verbose, header='Arrays are not equal')
   File "/Users/tjones/numpy.git/numpy/testing/utils.py", line 677, in
 assert_array_compare
     raise AssertionError(msg)
 AssertionError:
 Arrays are not equal

 (mismatch 50.0%)
  x: array([ 1.5,  1.5,  1.5,  1.5,  1.5,  1.5,  1.5,  1.5,  1.5,  1.5])
  y: array([ 2. ,  1.5,  1.5,  2. ,  1.5,  1.5,  2. ,  2. ,  2. ,  1.5])
 }}}

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/2144#comment:5>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list