Re: [Numpy-discussion] ufunc for sum of squared difference

2016-11-16 Thread Matthew Harrigan
Thanks for pointing me to that. I think its a great match for a 1D case, like the inner product of two arrays in terms of signature. I don't see how it works with higher dimensional arrays, esp with something like the axis parameter in ufunc.reduce. With what I proposed for an array of shape

Re: [Numpy-discussion] ufunc for sum of squared difference

2016-11-16 Thread Jerome Kieffer
On Mon, 14 Nov 2016 22:38:25 +0200 eat wrote: > but it's not so obvious what's happening "under the hoods". Consider this > (with an old Win7 machine): > Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 > bit (AMD64)] > np.__version__ > '1.11.1'

Re: [Numpy-discussion] ufunc for sum of squared difference

2016-11-14 Thread Stephan Hoyer
On Mon, Nov 14, 2016 at 5:40 PM, Matthew Harrigan < harrigan.matt...@gmail.com> wrote: > Essentially it creates a reduce for a function which isn't binary. I > think this would be generally useful. > NumPy already has a generic enough interface for creating such ufuncs. In fact, it's called a

Re: [Numpy-discussion] ufunc for sum of squared difference

2016-11-14 Thread Matthew Harrigan
Still slower and worse uses 2x the memory for the intermediate temporary array. I propose allowing implicit reductions with ufuncs. Specifically if out is provided with shape[axis] = 1, then pass it on to the ufunc with a stride of 0. That should allow this to work: x = np.arange(10) def

Re: [Numpy-discussion] ufunc for sum of squared difference

2016-11-14 Thread eat
Yeah, but it's not so obvious what's happening "under the hoods". Consider this (with an old Win7 machine): Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] np.__version__ '1.11.1' On Mon, Nov 14, 2016 at 10:38 AM, Jerome Kieffer

Re: [Numpy-discussion] ufunc for sum of squared difference

2016-11-14 Thread Jerome Kieffer
On Fri, 11 Nov 2016 11:25:58 -0500 Matthew Harrigan wrote: > I started a ufunc to compute the sum of square differences here > . > It is about 4x faster and uses half the memory compared to >

Re: [Numpy-discussion] ufunc for sum of squared difference

2016-11-11 Thread Matthew Harrigan
My possibly poorly thought out API would be something like np.add_sq_diff.set_c(42.0).reduce(x), basically add a setter method which returned self. Thanks for explaining what data was intended to do. All of this is really just a dance around the requirement that reduce only works on binary

Re: [Numpy-discussion] ufunc for sum of squared difference

2016-11-11 Thread Julian Taylor
here is an old unfinished PR adding max_abs which has a similar purpose as yours: https://github.com/numpy/numpy/pull/5509 So far I know data is set during runtime construction and is part of the ufunc object, so it is not really very suitable to pass in constants on call. Its intended purpose is

Re: [Numpy-discussion] ufunc for sum of squared difference

2016-11-11 Thread Matthew Harrigan
I started a ufunc to compute the sum of square differences here . It is about 4x faster and uses half the memory compared to np.sum(np.square(x-c)). This could significantly speed up common operations like std and var (where

Re: [Numpy-discussion] ufunc for sum of squared difference

2016-11-04 Thread Sebastian Berg
On Fr, 2016-11-04 at 15:42 -0400, Matthew Harrigan wrote: > I didn't notice identity before.  Seems like frompyfunc always sets > it to None.  If it were zero maybe it would work as desired here. > > In the writing your own ufunc doc, I was wondering if the pointer to > data could be used to get

Re: [Numpy-discussion] ufunc for sum of squared difference

2016-11-04 Thread Matthew Harrigan
I didn't notice identity before. Seems like frompyfunc always sets it to None. If it were zero maybe it would work as desired here. In the writing your own ufunc doc, I was wondering if the pointer to data could be used to get a constant at runtime. If not, what could that be used for? static

Re: [Numpy-discussion] ufunc for sum of squared difference

2016-11-04 Thread Sebastian Berg
On Fr, 2016-11-04 at 13:11 -0400, Matthew Harrigan wrote: > I was reading this and got thinking about if a ufunc could compute > the sum of squared differences in a single pass without a temporary > array.  The python code below demonstrates a possible approach. > > import numpy as np > x =