[C++-sig] bug in numarray (using take with character arrays) possibly affecting boost.python

Faheem Mitha faheem at email.unc.edu
Thu Apr 15 22:55:16 CEST 2004


For convenience the bug report is reproduced below.

The following wrapper to boost.python gives the same behaviour
described in the bug report, so I'm guessing that if boost.python used
the numarray implementation of `take' the bug will be there too.

In neither the numarray version or the boost.python version of take
does this bug show up for arrays of numerical values.

Boost.Python wrapper to take (in <boost/python/numeric.hpp>).
// Version of take obtained by calling Boost.Python take.
numeric::array mytake(numeric::array& y, const tuple& ind, int i)
  return extract<numeric::array>(y.take<tuple>(ind,i));


Bug report.
In [22]: import numarray.strings as str

In [23]: import numarray

In [24]: s = str.array(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',

In [25]: numarray.take(s,(1,2),axis=1)
ValueError                                Traceback (most recent call


/usr/lib/python2.3/site-packages/numarray/ufunc.py in take(array,
indices, axis, outarr, clipmode)
   1779             raise ValueError("indices must be a sequence")
   1780         work = _gen.swapaxes(array, 0, axis)
-> 1781         work = work._take((indices,), outarr=outarr,
   1782         return _gen.swapaxes(work, 0, axis)
   1783     else:

/usr/lib/python2.3/site-packages/numarray/generic.py in _take(self,
indices, **keywds)
    795     def _take(self, indices, **keywds):
    796         indices = list(indices)
--> 797         impliedShape, N = _takeShape(self, indices)
    798         result = self._clone(shape=impliedShape)
    799         indices = self._fix_pt_indices(indices)

/usr/lib/python2.3/site-packages/numarray/generic.py in
_takeShape(scattered, indexArrays)
    133         nShape = scattered._shape[-leftOver:]
    134         if scattered.isbyteswapped() or not
--> 135             raise ValueError("Invalid destination array:
partial indices require contiguous non-byteswapped destination")
    136     else:
    137         N = scattered._itemsize

ValueError: Invalid destination array: partial indices require
contiguous non-byteswapped destination

More information about the Cplusplus-sig mailing list