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

Robert Kern robert.kern@gmail....
Thu Jul 9 15:30:00 CDT 2009

On Thu, Jul 9, 2009 at 15:20, Fons Adriaensen<fons@kokkinizita.net> wrote:
> On Thu, Jul 09, 2009 at 12:00:23PM -0500, Robert Kern wrote:
>> On Thu, Jul 9, 2009 at 11:44, Fons Adriaensen<fons@kokkinizita.net> wrote:
>> > There is a simple rule which says that if you use an object
>> > pointer as a function argument you must INCREF it. This is
>> > just the logical consequence of using refcounted objects.
>> That's not true. There are many functions even in the standard Python
>> C API that "borrow" a reference.
> Indeed. Still, when calling a function Python will
> INCREF the arguments. And that's only logical since
> these arguments become local variables (i.e. a new
> reference) inside the called function and that function
> can do whatever it wants with them, including deleting
> or re-assigning them. Creating a function argument is
> not different from assigning to a new variable.
> This is also the reason why sys.getrefcount() will return
> a value that is one higher than the one in the caller's
> context.

That's not quite true. Forming the argument tuple increments the
count, not the call itself.

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco

More information about the NumPy-Discussion mailing list