<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 16, 2014 at 1:55 PM,  <span dir="ltr"><<a href="mailto:josef.pktd@gmail.com" target="_blank">josef.pktd@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span>On Tue, Sep 16, 2014 at 3:42 PM, Nathaniel Smith <<a href="mailto:njs@pobox.com" target="_blank">njs@pobox.com</a>> wrote:<br>
> On Tue, Sep 16, 2014 at 3:27 PM, Charles R Harris<br>
> <<a href="mailto:charlesr.harris@gmail.com" target="_blank">charlesr.harris@gmail.com</a>> wrote:<br>
>> Hi All,<br>
>><br>
>> It turns out that gufuncs will broadcast the last dimension if it is one.<br>
>> For instance, inner1d has signature `(n), (n) -> ()`, yet<br>
>><br>
>> In [27]: inner1d([1,1,1], [1])<br>
>> Out[27]: 3<br>
><br>
> Yes, this looks totally wrong to me too... broadcasting is a feature<br>
> of auto-vectorizing a core operation over a set of dimensions, it<br>
> shouldn't be applied to the dimensions of the core operation itself<br>
> like this.<br>
<br>
</span>Are these functions doing any numerical shortcuts in this case?<br>
<br>
If yes, this would be convenient.<br>
<br>
inner1d(x, weights)   with weights is either (n, ) or ()<br>
<br>
if weights == 1:<br>
    return x.sum()<br>
else:<br>
    return inner1d(x, weights)<br>
<span><font color="#888888"><br></font></span></blockquote><div><br></div><div>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.<br><br>In [4]: timeit inner1d(a, 1)<br>10000 loops, best of 3: 56.4 µs per loop<br><br>In [5]: timeit a.sum()<br>10000 loops, best of 3: 48.3 µs per loop<br><br></div><div>Chuck<br></div><div><br></div></div></div></div>