[Matrix-SIG] Numeric Nits
Rick White
rlw@stsci.edu
Tue, 22 Jun 1999 15:36:49 -0400 (EDT)
On Tue, 22 Jun 1999, Christopher J. Chase wrote:
>The problem is that the caller owns the reference. The numeric multiply
>routine has no idea who the caller is and what the caller will do with the
>reference, e.g. whether the caller is going to do a DECREF on return. Also
>the caller is not guaranteed to be the interpreter. Rather it could be a
>program using the C API.
Ah, I hadn't considered that possibility. You're right, that does
complicate things.
Suppose we just defined the behavior of the Numeric multiply, add, etc.
routines as depending on the reference count of the arguments, and
included this reuse of temporaries as part of the behavior?
Existing C code that calls the Numeric routines directly without
maintaining reference counts on arrays would have to change, and
maybe there is enough such code to make it a bad idea. But I
see this as a very desirable behavior that would be well worth adding
if the cost is not too high.
>One possible solution is if python objects could support an TEMPORARY
>attribute perhaps in the basic object_HEAD structure. Then a caller that
>will release an object after a call can mark an object as TEMPORARY, meaning
>"I (the caller) will not access this object and delete my reference to the
>object after the call)". Another meaning for TEMPORARY might be "Pending
>DECREF on return".
>
>A called function receiving an object as TEMPORARY and a reference count of
>one is allowed to overwrite or reuse the object.
This would require changing Python itself, not just Numeric, right?
Maybe we could convince Guido that this is worth dirtying up the
Python code, but I would probably resist it if I were him. Reuse
of temporaries is probably only an issue for Numeric (and maybe PIL
and other image modules), so it would be nice if it could be
handled by Numeric itself.
- Rick