[Numpy-discussion] Speeding up wxPython/numarray

Tim Hochberg tim.hochberg at cox.net
Thu Jul 1 11:52:05 EDT 2004


Todd Miller wrote:

>On Wed, 2004-06-30 at 19:00, Tim Hochberg wrote: 
>  
>
>>>>
>>>>        
>>>>
>>>FYI, the issue with tp_dealloc may have to do with which mode Python is
>>>compiled in, --with-pydebug, or not.  One approach which seems like it
>>>ought to work (just thought of this!) is to add an extra reference in C
>>>to the NumArray instance __dict__ (from NumArray.__init__ and stashed
>>>via a new attribute in the PyArrayObject struct) and then DECREF it as
>>>the last part of the tp_dealloc.  
>>> 
>>>
>>>      
>>>
>>That sounds promising.
>>    
>>
> <>
> I looked at this some, and while INCREFing __dict__ maybe the right
> idea, I forgot that there *is no* Python NumArray.__init__ anymore.
>
> So the INCREF needs to be done in C without doing any getattrs; this
> seems to mean calling a private _PyObject_GetDictPtr function to get a
> pointer to the __dict__ slot which can be dereferenced to get the
> __dict__.

Might there be a simpler way? Since you're putting an extra attribute on 
the PyArrayObject structure anyway, wouldn't it be possible to just 
stash _shadows there instead of the reference to the dictionary? It 
appears that that the only time _shadows is accessed from python is in 
__del__. If it were instead an attribute on ndarray, the dealloc problem 
would go away since the responsibility for deallocing it would fall to 
ndarray. Since everything else accesses it from C, that shouldn't be 
much of a problem and should speed that stuff up as well.

-tim







More information about the NumPy-Discussion mailing list