[Numpy-discussion] performing operations in-place in numpy

Pauli Virtanen pav at iki.fi
Thu Jul 9 04:41:51 EDT 2009


Thu, 09 Jul 2009 10:00:25 +0200, Matthieu Brucher kirjoitti:

> 2009/7/9 Citi, Luca <lciti at essex.ac.uk>:
>> Hello
>>
>> The problem is not PyArray_Conjugate itself. The problem is that
>> whenever you call a function from the C side and one of the inputs has
>> ref_count 1, it can be overwritten. This is not a problem from the
>> python side because if the ufunc sees a ref_count=1 it means that no
>> python object is referencing to it.
> 
> Does this also hold if you are using the Numpy API directly? Say I've
> decided to write some operation with the Numpy API, I will never have
> one of my arrays with ref_count == 1?

Newly created arrays have a refcount of 1, so this is a problem for
the C-API.

What needs to be ensured in Numpy is that none of the C-API functions can 
cause unexpected modification of their input arguments. So one would have 
to go through the list of exported functions, and check that none of them 
is problematic. (We know already that at least PyArray_Conjugate is.)

-- 
Pauli Virtanen




More information about the NumPy-Discussion mailing list