[Numpy-discussion] failed to add routine to the core module

marc marc.barbry at mailoo.org
Thu May 18 09:04:43 EDT 2017

Dear Numpy developers,

I'm trying to add a routine to calculate the sum of a product of two 
arrays (a dot product). But that would not increase the memory (from 
what I saw np.dot is increasing the memory while it should not be 
necessary). The idea is to avoid the use of the temporary array in the 
calculation of the variance ( numpy/numpy/core/_methods.py line 112).

The routine that I want to implement look like this in python,

|arr = np.random.rand(100000)|
|mean = arr.mean()|
|var = 0.0|
|for ai in arr: var += (ai-mean)**2|

I would like to implement it in the umath module. As a first step, I 
tried to reproduce the divmod function of umath, but I did not manage to 
do it, you can find my fork here 
<https://github.com/mbarbry/numpy/tree/looking_around> (the branch with 
the changes is call looking_around). During compilation I get the 
following error,

|gcc: numpy/core/src/multiarray/number.c
In file included from numpy/core/src/multiarray/number.c:17:0: 
numpy/core/src/multiarray/number.c: In function ‘array_sum_multiply’:
numpy/core/src/private/binop_override.h:176:39: error: ‘PyNumberMethods 
{aka struct <anonymous>}’ has no member named ‘nb_sum_multiply’ 
(void*)(Py_TYPE(m2)->tp_as_number->SLOT_NAME) != (void*)(test_func))
numpy/core/src/private/binop_override.h:180:13: note: in expansion of 
macro ‘BINOP_IS_FORWARD’ if (BINOP_IS_FORWARD(m1, m2, slot_expr, 
test_func) && \
numpy/core/src/multiarray/number.c:363:5: note: in expansion of macro 
nb_sum_multiply, array_sum_multiply);|

Sorry if my question seems basic, but I'm new in Numpy development.
Any help?

Thank you in advance,

Marc Barbry

PS: I opened an issues as well on the github repository
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20170518/991ee7b5/attachment.html>

More information about the NumPy-Discussion mailing list