[Numpy-discussion] ufunc and errors

Dag Sverre Seljebotn dagss@student.matnat.uio...
Sat Oct 3 03:24:44 CDT 2009


Robert Kern wrote:
> On Wed, Sep 30, 2009 at 09:34, Dag Sverre Seljebotn
> <dagss@student.matnat.uio.no> wrote:
>> I looked and looked in the docs, but couldn't find an answer to this:
>> When writing a ufunc, is it possible somehow to raise a Python exception
>> (by acquiring the GIL first to raise it, set a flag and a callback which
>> will be called with the GIL, or otherwise?).
> 
> You cannot acquire the GIL inside the loop. In order to do so, you
> would have to have access to the saved PyGILState_STATE which you
> don't.

I thought I could use PyGILState_Ensure (via Cython's "with gil" primitive):

http://docs.python.org/c-api/init.html?PyGILState_Ensure

(I've taken the rest of your email to heart, thanks.)


> 
>> Or should one always use
>> NaN even if the input does not make any sense (like, herhm, passing
>> anything but integers or half-integers to a Wigner 3j symbol).
> 
> You should use a NaN and ideally set the fpstatus to INVALID (creating
> the NaN may or may not do this; you will have to experiment). This
> will allow people to handle the issue as they wish using
> numpy.seterr(). An exception for just one value out of thousands is
> often undesirable.
> 
>> I know how I'd to it manually in a wrapper w/ passed in context if not,
>> but wanted to see.
>>
>> Also, will the arguments always be named x1, x2, x3, ..., or can I
>> somehow give them custom names?
> 
> The only place where names appear is in the docstring. Write whatever
> text you like.
> 


-- 
Dag Sverre


More information about the NumPy-Discussion mailing list