[Numpy-discussion] array.sum() slower than expected along some array axes?

Keith Goodman kwgoodman at gmail.com
Sun Feb 4 15:00:26 EST 2007


On 2/4/07, Sebastian Haase <haase at msg.ucsf.edu> wrote:
> On 2/3/07, Robert Kern <robert.kern at gmail.com> wrote:
> > Stephen Simmons wrote:
> >
> > > The question though is whether all of the inner loop's overhead is
> > > necessary.
> > > My counterexample using numpy.dot() suggests there's considerable scope
> > > for improvement, at least for certain common cases.
> >
> > Well, yes. You most likely have an ATLAS-accelerated dot(). The ATLAS put a lot
> > of work into making matrix products really fast. However, they did so at a cost:
> > different architectures use different code. That's not really something we can
> > do in the core of numpy without making numpy as difficult to build as ATLAS is.
> >
> Maybe this argument could be inverted:
> maybe numpy could check if ATLAS is installed and automatically switch to the
> numpy.dot(numpy.ones(a.shape[0], a.dtype), a)
> variant that Stephen suggested.
>
> Of course -- as I see it -- the numpy.ones(...)  part requires lots of
> extra memory. Maybe there are other downsides ... !?

I use multiplication instead of sum in heavily used loops. I'm often
able to predefine the ones outside the loop.

In Octave I made my own sum functions---separate ones for axis 0 and
1---that use multiplication. Maybe it is better to make a new function
rather than complicate the existing one.



More information about the NumPy-Discussion mailing list