[Numpy-discussion] How to tell if PyArray_FromAny has copied data?
oliphant.travis at ieee.org
Sun Mar 12 19:13:02 CST 2006
Zachary Pincus wrote:
> Hi folks,
> I need to figure out how to tell if PyArray_FromAny() has made a copy
> of the data that was provided to it.
> I assume that if the returned PyObject has a different address than
> the input object, then a copy was made somewhere along the line. Is
> this true? Is there a better way to tell?
If an array object was passed in, then this will work. If, however,
another object was passed in that exposes the array interface which
allows data sharing, then you will get a new ArrayObject but it will
share the same array data so no copying will have been done. You will
be able to tell, because the returned object won't own it's own data.
So, it depends on what you are going to be inputing and what kind of
data sharing you are going to be checking for.
> Alternately, I guess I could just inspect the input array object to
> see if it is exactly what I want, and branch on that. But running
> things through PyArray_FromAny seems easier, if it is possible.
This actually might be easier as PyArray_FromAny can take any Python
object whereas you seem to already know you have an array input.
More information about the Numpy-discussion