<div dir="ltr"><br><br>On Wednesday, February 19, 2014 9:10:03 AM UTC+1, Stefan Behnel wrote:<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">>> Nathaniel Smith wrote:
<br>>>> Does anyone see any issue we might be overlooking in this refcount == 1
<br>>>> optimization for the python api? I'll post a PR with the change shortly.
<br>>>> It occurs belatedly that Cython code like a = np.arange(10)
<br>>>> b = np.arange(10)
<br>>>> c = a + b might end up calling tp_add with refcnt 1 arrays. Ditto for
<br>>>> same with cdef np.ndarray or cdef object added. We should check...
<br>That can happen, yes. Cython only guarantees that the object it passes is
<br>safely owned so that the reference cannot go away while it's being
<br>processed by a function. If it's in a local (non-closure) variable (or
<br>Cython temporary variable), that guarantee holds, so it's safe to pass
<br>objects with only a single reference into a C function, and Cython will do
<br></blockquote><div><br><br>thats unfortunate, it would be a quite significant improvement to numpy (~30% improvement to all operations involving temporaries).<br>Is increasing the reference count before going into PyNumber functions really that expensive that its worth avoiding?<br></div></div>