[Numpy-discussion] Type casting problems with numpy.take

Jaime Fernández del Río jaime.frio@gmail....
Sat Feb 9 00:27:44 CST 2013

On Fri, Feb 8, 2013 at 6:44 PM, Charles R Harris

> My money is on 'five year old bug'.

A bug indeed it seems to be. I have cloned the source code, and in
item_selection.c, in function PyArray_TakeFrom, when 'out' is an argument
in the call, the code is actually trying to cast 'out' to the type of
'self' (the first array in the call to take):

dtype = PyArray_DESCR(self);
obj = (PyArrayObject *)PyArray_FromArray(out, dtype, flags);

I have also been looking at PyArray_FromArray in ctors.c, and it would be
very easy to fix the broken behaviour, by adding NPY_ARRAY_FORCECAST to the
flags in the call to PyArray_FromArray, the casting mode would be changed
to NPY_UNSAFE_CASTING, and that should do away with the error.

I'm not sure if a smarter type checking is in order here, that would
require a more in depth redoing of how PyArray_TakeFrom operates. In think
ufuncs let you happily cast unsafely, so maybe take should just be the
same? Or should 'self' should be cast to the type of 'out'? Would that
break anything else?

But if nothing else, the above fix should just make the current possibly
dysfunctional typecasting a consistent feature of numpy, which would be
better than what's going on right now.

So, where do I go to file a bug report? Should I try to send the above
proposed change as a patch? I am not sure how to do either thing, any
reference explaining it a little more in depth that you can point me to?

> Many basic numpy functions are not well tested. Writing tests is a tedious
> job but doesn't require any C foo, just Python an patience, so if anyone
> would like to get involved...

How does one get involved?

( O.o)
( > <) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus planes
de dominación mundial.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20130208/2bf3d4f9/attachment-0001.html 

More information about the NumPy-Discussion mailing list