Re: [Numpy-discussion] odd performance of sum?

2011-02-13 Thread Sturla Molden
Den 13.02.2011 04:30, skrev Travis Oliphant: One of the advantages of an open source community is that different needs get addressed by the people who need them. So, if you really need a faster sum and are willing to do the hard work to make it happen (or convince someone else to do it for

Re: [Numpy-discussion] odd performance of sum?

2011-02-13 Thread Sturla Molden
Den 13.02.2011 01:02, skrev eat: Now, I'm not pretending to know what kind of a person a 'typical' numpy user is. But I'm assuming that there just exists more than me with roughly similar questions in their (our) minds and who wish to utilize numpy more 'pythonic; all batteries included' way.

Re: [Numpy-discussion] odd performance of sum?

2011-02-12 Thread Travis Oliphant
I think everybody would be happy if .sum() were as fast as possible, and patches for review are always welcome. There are distinct things that could be done to improve the performance of ufuncs and their methods as several people have shown.In fact, there is a lot of low-hanging fruit ins

Re: [Numpy-discussion] odd performance of sum?

2011-02-12 Thread eat
Hi Sturla, On Sat, Feb 12, 2011 at 5:38 PM, Sturla Molden wrote: > Den 10.02.2011 16:29, skrev eat: > > One would expect sum to outperform dot with a clear marginal. Does > > there exixts any 'tricks' to increase the performance of sum? > First of all, thanks for you still replying. Well, I'm st

Re: [Numpy-discussion] odd performance of sum?

2011-02-12 Thread Sturla Molden
Den 10.02.2011 16:29, skrev eat: > One would expect sum to outperform dot with a clear marginal. Does > there exixts any 'tricks' to increase the performance of sum? I see that others have ansvered already. The ufunc np.sum is not going going to beat np.dot. You are racing the heavy machinery of

Re: [Numpy-discussion] odd performance of sum?

2011-02-11 Thread Pauli Virtanen
Thu, 10 Feb 2011 20:49:28 +, Pauli Virtanen wrote: [clip] > 1. Check first if the bottleneck is in the inner reduction loop > (function DOUBLE_add in loops.c.src:712) or in the outer iteration > (function PyUFunc_ReductionOp in ufunc_object.c:2781). > 2. If it's in the inner loop, some optim

Re: [Numpy-discussion] odd performance of sum?

2011-02-10 Thread eat
Hi, On Fri, Feb 11, 2011 at 12:08 AM, Robert Kern wrote: > On Thu, Feb 10, 2011 at 15:32, eat wrote: > > Hi Robert, > > > > On Thu, Feb 10, 2011 at 10:58 PM, Robert Kern > wrote: > >> > >> On Thu, Feb 10, 2011 at 14:29, eat wrote: > >> > Hi Robert, > >> > > >> > On Thu, Feb 10, 2011 at 8:16

Re: [Numpy-discussion] odd performance of sum?

2011-02-10 Thread Charles R Harris
On Thu, Feb 10, 2011 at 3:08 PM, Robert Kern wrote: > On Thu, Feb 10, 2011 at 15:32, eat wrote: > > Hi Robert, > > > > On Thu, Feb 10, 2011 at 10:58 PM, Robert Kern > wrote: > >> > >> On Thu, Feb 10, 2011 at 14:29, eat wrote: > >> > Hi Robert, > >> > > >> > On Thu, Feb 10, 2011 at 8:16 PM, Rob

Re: [Numpy-discussion] odd performance of sum?

2011-02-10 Thread Charles R Harris
On Thu, Feb 10, 2011 at 2:26 PM, Mark Wiebe wrote: > On Thu, Feb 10, 2011 at 10:31 AM, Pauli Virtanen wrote: > >> Thu, 10 Feb 2011 12:16:12 -0600, Robert Kern wrote: >> [clip] >> > One thing that might be worthwhile is to make >> > implementations of sum() and cumsum() that avoid the ufunc machi

Re: [Numpy-discussion] odd performance of sum?

2011-02-10 Thread Robert Kern
On Thu, Feb 10, 2011 at 15:32, eat wrote: > Hi Robert, > > On Thu, Feb 10, 2011 at 10:58 PM, Robert Kern wrote: >> >> On Thu, Feb 10, 2011 at 14:29, eat wrote: >> > Hi Robert, >> > >> > On Thu, Feb 10, 2011 at 8:16 PM, Robert Kern >> > wrote: >> >> >> >> On Thu, Feb 10, 2011 at 11:53, eat wrot

Re: [Numpy-discussion] odd performance of sum?

2011-02-10 Thread eat
Hi Robert, On Thu, Feb 10, 2011 at 10:58 PM, Robert Kern wrote: > On Thu, Feb 10, 2011 at 14:29, eat wrote: > > Hi Robert, > > > > On Thu, Feb 10, 2011 at 8:16 PM, Robert Kern > wrote: > >> > >> On Thu, Feb 10, 2011 at 11:53, eat wrote: > >> > Thanks Chuck, > >> > > >> > for replying. But don

Re: [Numpy-discussion] odd performance of sum?

2011-02-10 Thread Mark Wiebe
On Thu, Feb 10, 2011 at 10:31 AM, Pauli Virtanen wrote: > Thu, 10 Feb 2011 12:16:12 -0600, Robert Kern wrote: > [clip] > > One thing that might be worthwhile is to make > > implementations of sum() and cumsum() that avoid the ufunc machinery and > > do their iterations more quickly, at least for

Re: [Numpy-discussion] odd performance of sum?

2011-02-10 Thread Robert Kern
On Thu, Feb 10, 2011 at 14:51, Joshua Holbrook wrote: > Maybe I'm missing something, but why not just implement sum() using > dot() and ones() ? You can't do everything that sum() does with just dot() and ones(). -- Robert Kern "I have come to believe that the whole world is an enigma, a harml

Re: [Numpy-discussion] odd performance of sum?

2011-02-10 Thread Robert Kern
On Thu, Feb 10, 2011 at 14:29, eat wrote: > Hi Robert, > > On Thu, Feb 10, 2011 at 8:16 PM, Robert Kern wrote: >> >> On Thu, Feb 10, 2011 at 11:53, eat wrote: >> > Thanks Chuck, >> > >> > for replying. But don't you still feel very odd that dot outperforms sum >> > in >> > your machine? Just to

Re: [Numpy-discussion] odd performance of sum?

2011-02-10 Thread Joshua Holbrook
Maybe I'm missing something, but why not just implement sum() using dot() and ones() ? --Josh On Thu, Feb 10, 2011 at 11:49 AM, Pauli Virtanen wrote: > On Thu, 10 Feb 2011 22:38:52 +0200, eat wrote: > [clip] >> I hope so. Please suggest if there's anything that I can do to further >> advance thi

Re: [Numpy-discussion] odd performance of sum?

2011-02-10 Thread Pauli Virtanen
On Thu, 10 Feb 2011 22:38:52 +0200, eat wrote: [clip] > I hope so. Please suggest if there's anything that I can do to further > advance this. (My C skills are allready bit rusty, but at any higher > level I'll try my best to contribute). If someone wants to try to improve the situation, here's a

Re: [Numpy-discussion] odd performance of sum?

2011-02-10 Thread eat
Hi Pauli, On Thu, Feb 10, 2011 at 8:31 PM, Pauli Virtanen wrote: > Thu, 10 Feb 2011 12:16:12 -0600, Robert Kern wrote: > [clip] > > One thing that might be worthwhile is to make > > implementations of sum() and cumsum() that avoid the ufunc machinery and > > do their iterations more quickly, at

Re: [Numpy-discussion] odd performance of sum?

2011-02-10 Thread eat
Hi Robert, On Thu, Feb 10, 2011 at 8:16 PM, Robert Kern wrote: > On Thu, Feb 10, 2011 at 11:53, eat wrote: > > Thanks Chuck, > > > > for replying. But don't you still feel very odd that dot outperforms sum > in > > your machine? Just to get it simply; why sum can't outperform dot? > Whatever >

Re: [Numpy-discussion] odd performance of sum?

2011-02-10 Thread Pauli Virtanen
Thu, 10 Feb 2011 12:16:12 -0600, Robert Kern wrote: [clip] > One thing that might be worthwhile is to make > implementations of sum() and cumsum() that avoid the ufunc machinery and > do their iterations more quickly, at least for some common combinations > of dtype and contiguity. I wonder what i

Re: [Numpy-discussion] odd performance of sum?

2011-02-10 Thread Robert Kern
On Thu, Feb 10, 2011 at 11:53, eat wrote: > Thanks Chuck, > > for replying. But don't you still feel very odd that dot outperforms sum in > your machine? Just to get it simply; why sum can't outperform dot? Whatever > architecture (computer, cache) you have, it don't make any sense at all that > w

Re: [Numpy-discussion] odd performance of sum?

2011-02-10 Thread eat
Thanks Chuck, for replying. But don't you still feel very odd that dot outperforms sum in your machine? Just to get it simply; why sum can't outperform dot? Whatever architecture (computer, cache) you have, it don't make any sense at all that when performing significantly less instructions, you'll

Re: [Numpy-discussion] odd performance of sum?

2011-02-10 Thread Charles R Harris
On Thu, Feb 10, 2011 at 8:29 AM, eat wrote: > Hi, > > Observing following performance: > In []: m= 1e5 > In []: n= 1e2 > In []: o= ones(n) > In []: M= randn(m, n) > In []: timeit M.sum(1) > 10 loops, best of 3: 38.3 ms per loop > In []: timeit dot(M, o) > 10 loops, best of 3: 21.1 ms per loop > >

[Numpy-discussion] odd performance of sum?

2011-02-10 Thread eat
Hi, Observing following performance: In []: m= 1e5 In []: n= 1e2 In []: o= ones(n) In []: M= randn(m, n) In []: timeit M.sum(1) 10 loops, best of 3: 38.3 ms per loop In []: timeit dot(M, o) 10 loops, best of 3: 21.1 ms per loop In []: m= 1e2 In []: n= 1e5 In []: o= ones(n) In []: M= randn(m, n) I