[NumPy-Tickets] [NumPy] #2122: numpy.take gives corrupted result with inplace operation
NumPy Trac
numpy-tickets@scipy....
Sun Apr 29 18:20:46 CDT 2012
#2122: numpy.take gives corrupted result with inplace operation
-------------------------+--------------------------------------------------
Reporter: rainwoodman | Owner: somebody
Type: defect | Status: new
Priority: high | Milestone: Unscheduled
Component: numpy.core | Version: 1.6.1
Keywords: |
-------------------------+--------------------------------------------------
Take doesn't work as expected when the output is inplace.
When mode='clip' or mode='wrap', the operation is truly in-place,
and the simple take algorithm currently implemented will overwrite the
array elements before they are memmoved to the correct reindexed
positions.
A simple test case is listed below,
In [37]: a = array([0, 1, 2])
In [38]: ind = array([2, 1, 0])
In [39]: b = a.copy()
In [40]: a.take(ind, out=a)
Out[40]: array([2, 1, 0])
In [41]: a = b.copy()
In [42]: a.take(ind, out=a, mode='clip')
Out[42]: array([2, 1, 2])
Out[40] is correct, for mode='raise' secretly creates a copy of the output
before copying. But Out[42] is in-correct. No error or warning is given.
A fix is either to create a copy for the other two modes, or to actually
use a permuting algorithm. The latter calls for a full rewrite of
PyArray_Take but will save memory usage significantly.
A proper implementation is used in GSL: gsl_permute.
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/2122>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list