<div dir="ltr"><div>Hi,<br><br>Here is another example.<br><br>To write pix2ang (and similar functions) to a ufunc, one may want to have implicit scalar broadcast on `nested` and `nsides` arguments.<br><br>The function is described here:<br><br><a href="http://healpy.readthedocs.org/en/latest/generated/healpy.pixelfunc.pix2ang.html#healpy.pixelfunc.pix2ang">http://healpy.readthedocs.org/en/latest/generated/healpy.pixelfunc.pix2ang.html#healpy.pixelfunc.pix2ang</a><br><br><br></div>Yu<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 17, 2016 at 2:04 AM, Travis Oliphant <span dir="ltr"><<a href="mailto:travis@continuum.io" target="_blank">travis@continuum.io</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Wed, Mar 16, 2016 at 3:07 PM, Charles R Harris <span dir="ltr"><<a href="mailto:charlesr.harris@gmail.com" target="_blank">charlesr.harris@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span>On Wed, Mar 16, 2016 at 1:48 PM, Travis Oliphant <span dir="ltr"><<a href="mailto:travis@continuum.io" target="_blank">travis@continuum.io</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span>On Wed, Mar 16, 2016 at 12:55 PM, Nathaniel Smith <span dir="ltr"><<a href="mailto:njs@pobox.com" target="_blank">njs@pobox.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">Hi Travis,</p><span>
<p dir="ltr">On Mar 16, 2016 9:52 AM, "Travis Oliphant" <<a href="mailto:travis@continuum.io" target="_blank">travis@continuum.io</a>> wrote:<br>
><br>
> Hi everyone,<br>
><br>
> Can you help me understand why the stricter changes to generalized ufunc argument checking no now longer allows scalars to be interpreted as 1-d arrays in the core-dimensions? <br>
><br>
> Is there a way to specify in the core-signature that scalars should be allowed and interpreted in those cases as an array with all the elements the same?   This seems like an important feature. </p>
</span><p dir="ltr">Can you share some example of when this is useful?</p></blockquote><div><br></div></span><div>Being able to implicitly broadcast scalars to arrays is the core-function of broadcasting.    This is still very useful when you have a core-kernel an want to pass in a scalar for many of the arguments.   It seems that at least in that case, automatic broadcasting should be allowed --- as it seems clear what is meant.</div><div><br></div><div>While you can use the broadcast* features to get the same effect with the current code-base, this is not intuitive to a user who is used to having scalars interpreted as arrays in other NumPy operations. <br></div></div></div></div></blockquote><div><br></div></span><div>The `@` operator doesn't allow that.<br> <br></div><span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div></div><div><br></div><div>It used to automatically happen and a few people depended on it in several companies and so the 1.10 release broke their code. <br></div><div><br></div><div>I can appreciate that in the general case, allowing arbitrary broadcasting on the internal core dimensions can create confusion.  But, scalar broadcasting still makes sense. </div></div></div></div></blockquote><div><br></div></span><div>Mixing array multiplications with scalar broadcasting is looking for trouble. Array multiplication needs strict dimensions and having stacked arrays and vectors was one of the prime objectives of gufuncs. Perhaps what we need is a more precise notation for broadcasting, maybe `*` or some such addition to the signaturs to indicate that scalar broadcasting is acceptable.<br></div></div></div></div></blockquote><div><br></div></span><div>I think that is a good idea.    Let the user decide if scalar broadcasting is acceptable for their function. </div><div><br></div><div>Here is a simple concrete example where scalar broadcasting makes sense:   </div><div><br></div><div>A 1-d dot product (the core of np.inner)   (k), (k) -> ()</div><div><br></div><div>A user would assume they could call this function with a scalar in either argument and have it broadcast to a 1-d array.    Of course, if both arguments are scalars, then it doesn't make sense.  </div><div><br></div><div>Having a way for the user to allow scalar broadcasting seems sensible and a nice compromise. </div><div><br></div><div>-Travis</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div> <snip><br><br></div><div>Chuck<br></div><br></div></div></div><span class="">
<br>_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org" target="_blank">NumPy-Discussion@scipy.org</a><br>
<a href="https://mail.scipy.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
<br></span></blockquote></div><span class=""><br><br clear="all"><div><br></div>-- <br><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><div style="font-size:12.8000001907349px;color:rgb(136,136,136)"><b><br>Travis Oliphant, PhD</b></div><div style="font-size:12.8000001907349px;color:rgb(136,136,136)"><i>Co-founder and CEO</i></div><div style="font-size:12.8000001907349px;color:rgb(136,136,136)"><i><br></i></div><div style="font-size:12.8000001907349px;color:rgb(136,136,136)"><img src="https://docs.google.com/a/continuum.io/uc?id=0B8_D9l6ZUhNIaF9HbGZSV09TNHc&export=download" height="37" width="200"></div></div><div style="font-size:12.8000001907349px;color:rgb(136,136,136)"><br></div><div style="font-size:12.8000001907349px;color:rgb(136,136,136)">@teoliphant</div><div style="font-size:12.8000001907349px;color:rgb(136,136,136)"><a href="tel:512-222-5440" value="+15122225440" target="_blank">512-222-5440</a></div><div style="font-size:12.8000001907349px;color:rgb(136,136,136)"><a href="http://www.continuum.io" target="_blank">http://www.continuum.io</a></div></div></div></div></div></div></div></div>
</span></div></div>
<br>_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="https://mail.scipy.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
<br></blockquote></div><br></div>