Re: [Numpy-discussion] Ensuring one can operate on array-like argument in place

2016-11-14 Thread Chris Barker
I tend to use ndarray.copy() in python code -- no reason you couldn't do the same in Cython. If you want to take any array-like object that may not have a copy() method, you could call asanyarray() first: -CHB On Sat, Nov 12, 2016 at 9:00 AM, Pavlyk, Oleksandr < oleksandr.pav...@intel.com> w

Re: [Numpy-discussion] Ensuring one can operate on array-like argument in place

2016-11-13 Thread Pauli Virtanen
Sat, 12 Nov 2016 17:00:07 +, Pavlyk, Oleksandr kirjoitti: [clip] > if x_arr is not x: >in_place = 1 # a copy was made, so we can work in place. > > The logic is of the last line turns out to be incorrect, because the > input x can be a class with an array interface. Please see:

[Numpy-discussion] Ensuring one can operate on array-like argument in place

2016-11-12 Thread Pavlyk, Oleksandr
Hi, In my Cython code a function processes it argument x as follows: x_arr = PyArray_CheckFromAny( x, NULL, 0, 0, cnp.NPY_ELEMENTSTRIDES | cnp.NPY_ENSUREARRAY | cnp.NPY_NOTSWAPPED, NULL) if x_arr is not x: in_place = 1 # a copy was made, so we can work in pla