[Numpy-discussion] performing operations in-place in numpy
Pauli Virtanen
pav+sp@iki...
Thu Jul 9 15:17:44 CDT 2009
On 2009-07-09, Citi, Luca <lciti@essex.ac.uk> wrote:
> Let me see if I understand correctly...
> what you suggest is something like:
> 1) adding an argument flag to construct_arrays
> that enables/disables the feature
> 2) adding the same argument flag to construct_loop which
> is passed untouched to construct_arrays
> 3) set the flag to "disable" in the construct_loop call inside
> PyUFunc_GenericFunction
> 4) write an exact copy of PyUFunc_GenericFunction with the flag
> "enabled"
> 5) in ufunc_generic_call, call the latter instead of
> PyUFunc_GenericFunction
> Am I correct?
>
> Sounds doable to me as long as ufunc.__call__ is not
> directly or indirectly [used] in the numpy C API.
It's conceivable that someone would call
PyObject_Call(ufunc, args, kw)
from C code. But this is already a bit contrived, given that
PyUFunc_GenericFunction is there, and the args tuple probably
usually has new references of the contained objects.
[CPython itself creates a new tuple when doing
a = (np.zeros((4,)), np.zeros((5,)))
np.add(*a)
so that also in this case the refcounts of the two arrays in the
tuple are > 1.]
--
Pauli Virtanen
More information about the NumPy-Discussion
mailing list