[Numpy-discussion] [cython-users] Re: avoiding numpy temporaries via refcount

jtaylor.debian at googlemail.com jtaylor.debian at googlemail.com
Thu Feb 20 17:54:30 EST 2014



On Wednesday, February 19, 2014 9:10:03 AM UTC+1, Stefan Behnel wrote:
>
> >> Nathaniel Smith wrote: 
> >>> Does anyone see any issue we might be overlooking in this refcount == 
> 1 
> >>> optimization for the python api? I'll post a PR with the change 
> shortly. 
> >>> 
> >>> It occurs belatedly that Cython code like   a = np.arange(10) 
> >>>   b = np.arange(10) 
> >>>   c = a + b might end up calling tp_add with refcnt 1 arrays. Ditto 
> for 
> >>> same with cdef np.ndarray or cdef object added. We should check... 
>
> That can happen, yes. Cython only guarantees that the object it passes is 
> safely owned so that the reference cannot go away while it's being 
> processed by a function. If it's in a local (non-closure) variable (or 
> Cython temporary variable), that guarantee holds, so it's safe to pass 
> objects with only a single reference into a C function, and Cython will do 
> that. 
>
> Stefan 
>


thats unfortunate, it would be a quite significant improvement to numpy 
(~30% improvement to all operations involving temporaries).
Is increasing the reference count before going into PyNumber functions 
really that expensive that its worth avoiding?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20140220/67e05178/attachment.html>


More information about the NumPy-Discussion mailing list