On Tue, Sep 16, 2014 at 1:55 PM, <josef.p...@gmail.com> wrote: > On Tue, Sep 16, 2014 at 3:42 PM, Nathaniel Smith <n...@pobox.com> wrote: > > On Tue, Sep 16, 2014 at 3:27 PM, Charles R Harris > > <charlesr.har...@gmail.com> wrote: > >> Hi All, > >> > >> It turns out that gufuncs will broadcast the last dimension if it is > one. > >> For instance, inner1d has signature `(n), (n) -> ()`, yet > >> > >> In [27]: inner1d([1,1,1], [1]) > >> Out[27]: 3 > > > > Yes, this looks totally wrong to me too... broadcasting is a feature > > of auto-vectorizing a core operation over a set of dimensions, it > > shouldn't be applied to the dimensions of the core operation itself > > like this. > > Are these functions doing any numerical shortcuts in this case? > > If yes, this would be convenient. > > inner1d(x, weights) with weights is either (n, ) or () > > if weights == 1: > return x.sum() > else: > return inner1d(x, weights) > > That depends on the inner inner loop ;) Currently inner1d inner loop multiplies and adds so not as efficient as a sum in the scalar case. However, it is probably faster than an if statement.
In [4]: timeit inner1d(a, 1) 10000 loops, best of 3: 56.4 µs per loop In [5]: timeit a.sum() 10000 loops, best of 3: 48.3 µs per loop Chuck
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion