On Fri, 11 Nov 2016 11:25:58 -0500
Matthew Harrigan <harrigan.matt...@gmail.com> wrote:

> I started a ufunc to compute the sum of square differences here
> <https://gist.github.com/mattharrigan/6f678b3d6df5efd236fc23bfb59fd3bd>.
> It is about 4x faster and uses half the memory compared to
> np.sum(np.square(x-c)). 

Hi Matt,

Using *blas* you win already a factor two (maybe more depending on you blas 
implementation):

% python -m timeit -s "import numpy as np;x=np.linspace(0,1,int(1e7))" 
"np.sum(np.square(x-2.))"
10 loops, best of 3: 135 msec per loop

% python -m timeit -s "import numpy as np;x=np.linspace(0,1,int(1e7))" 
"y=x-2.;np.dot(y,y)"
10 loops, best of 3: 70.2 msec per loop


Cheers,
-- 
Jérôme Kieffer
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to