User guide

NumPy User Guide, Release 1.9.0
An array of pointers to the actual data for the input and output arrays. The input arguments
are given first followed by the output arguments.
dimensions
A pointer to the size of the dimension over which this function is looping.
steps
A pointer to the number of bytes to jump to get to the next element in this dimension for
each of the input and output arguments.
data
Arbitrary data (extra arguments, function names, etc. ) that can be stored with the ufunc
and will be passed in when it is called.
static void
double_add(char
*
args, npy_intp
*
dimensions, npy_intp
*
steps,
void
*
extra)
{
npy_intp i;
npy_intp is1 = steps[0], is2 = steps[1];
npy_intp os = steps[2], n = dimensions[0];
char
*
i1 = args[0],
*
i2 = args[1],
*
op = args[2];
for (i = 0; i < n; i++) {
*
((double
*
)op) =
*
((double
*
)i1) +
*
((double
*
)i2);
i1 += is1;
i2 += is2;
op += os;
}
}
data
An array of data. There should be ntypes entries (or NULL) one for every loop function defined
for this ufunc. This data will be passed in to the 1-d loop. One common use of this data variable is to
pass in an actual function to call to compute the result when a generic 1-d loop (e.g. PyUFunc_d_d)
is being used.
types
An array of type-number signatures (type char ). This array should be of size (nin+nout)*ntypes
and contain the data-types for the corresponding 1-d loop. The inputs should be first followed by the
outputs. For example, suppose I have a ufunc that supports 1 integer and 1 double 1-d loop (length-2
func and data arrays) that takes 2 inputs and returns 1 output that is always a complex double, then
the types array would be
static char types[3] = {NPY_INT, NPY_DOUBLE, NPY_CDOUBLE}
The bit-width names can also be used (e.g. NPY_INT32, NPY_COMPLEX128 ) if desired.
ntypes
The number of data-types supported. This is equal to the number of 1-d loops provided.
nin
The number of input arguments.
nout
The number of output arguments.
5.3. Writing your own ufunc 97