[Numpy-discussion] how is y += x computed when y.strides = (0, 8) and x.strides=(16, 8) ?

David Cournapeau cournape at gmail.com
Wed Oct 17 20:58:02 EDT 2012

On Wed, Oct 17, 2012 at 11:38 AM, Sebastian Walter
<sebastian.walter at gmail.com> wrote:
> I'd like to have a look at the implementation of iadd in numpy,
> but I'm having a real hard time to find the corresponding code.
> I'm basically stuck at
> https://github.com/numpy/numpy/blob/master/numpy/core/src/multiarray/number.c#L487

n_ops is essentially a map of function pointers set in the umath
module (see PyArray_SetNumericOps, used in umath module). IOW,
n_ops.add is a pointer to umath.add, itself set up through a generated
file __umath_generated.c:

 f = PyUFunc_FromFuncAndData(add_functions, ...);
 PyDict_SetItemString(dictionary, "add", f);

At that point, you need to look into the ufunc machinery: for double
all along, the add type resolver should be pretty simple and in the
end call DOUBLE_add.

> Could someone give me a pointer where to find it?
> Respectively, could someone point me to some documentation where the
> (folder/file) structure of the numpy sources is explained?

There is sadly not much explanation on the code structure for the C
part. src/multiarray contains the code for the multiarray extension
(array, dtype, broadcasting, iteration) and src/umath contains the
code for the umath extension (ufunc machinery + core loops


More information about the NumPy-Discussion mailing list