[Numpy-discussion] Writing new ufuncs

Robert Kern robert.kern@gmail....
Sun May 11 22:05:39 CDT 2008

On Sun, May 11, 2008 at 9:50 PM, Anne Archibald
<peridot.faceted@gmail.com> wrote:
> 2008/5/11 Robert Kern <robert.kern@gmail.com>:
>> Basically, you need 3 arrays: functions implementing the type-specific
>> inner loops, void* extra data to pass to these functions, and an array
>> of arrays containing the type signatures of the ufunc. In numpy, we
>> already have generic implementations of the loop functions for common
>> combinations of types. In your case, for a binary function taking two
>> doubles and returning a double, we have PyUFunc_dd_d(). As its extra
>> void* data, it takes a function pointer that actually implements the
>> element-wise operation. So lets start making the arrays:
> Great! Thanks!
> Is it possible to provide a specialized implementation of reduce()?
> (Since reduce() can be implemented more efficiently than doing it
> pairwise.)

I don't think so, no.

>>            PyUFunc_None,  // The identity element for reduction.
>>                           // No good one to use for this function,
>>                           // unfortunately.
> Is it safe to use minus infinity, or is this going to give people all
> kinds of warnings if they have seterr() set?

Perhaps, but ufuncs only allow 0 or 1 for this value, currently.

Also, I was wrong about using PyUFunc_ff_f. Instead, use PyUFunc_ff_f_As_dd_d.

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
 -- Umberto Eco

More information about the Numpy-discussion mailing list