[Matrix-SIG] Numeric Nits
Rick White
rlw@stsci.edu
Tue, 22 Jun 1999 14:30:47 -0400 (EDT)
>On Tue, 22 Jun 1999, David Ascher wrote:
>
>It's an interesting approach. However, I don't think that the "Suppose
>..." statement above corresponds to an "if and only if", which I believe
>is needed. Consider:
>
> a = arange(10)
> b = a * 3
> return a, b
>
>At the point of the PyArray_Multiply, the refcount of its first argument
>(a) is 1. However, it is not a temporary variable. Or did I miss
>something?
I think the refcount for (a) would be 2, one for the reference
held by the variable 'a' and one for the reference on the stack.
If the refcount were only 1, then the DECREF would reduce it
to zero, allowing a to be released.
I think the only time an argument to multiply (or other operator)
can have a refcount of 1 is when it is temporary storage about
to be released. E.g.
a = (b*c)*d
During the first multiply (b*c), both arguments have refcount > 1
so a new Numeric array gets allocated for the result. But for the
second multiply the first argument will have a refcount of 1,
indicating that it is available for reuse.
I'm hoping somebody will tell me if I'm wrong (or even if I'm
right!) As Konrad Hinsen suggested, I'm playing a bit with
UserArray to see if I can get it to reuse temporaries like this.