<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>+1<br><br><span style="font-size: 13pt; background-color: rgba(255, 255, 255, 0);">John ZuHone</span><div><span style="font-size: 13pt;">Harvard-Smithsonian Center for Astrophysics </span></div><div><div><span style="background-color: rgba(255, 255, 255, 0);"><br>60 Garden St., MS-67</span></div><div><span style="background-color: rgba(255, 255, 255, 0);">Cambridge, MA 02138<br>(w) 617-496-1816</span></div><div><span style="background-color: rgba(255, 255, 255, 0);">(m) <a href="tel:781-708-5004" x-apple-data-detectors="true" x-apple-data-detectors-type="telephone" x-apple-data-detectors-result="1/2">781-708-5004</a><br><a href="mailto:jzuhone@cfa.harvard.edu">jzuhone@cfa.harvard.edu</a></span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><a href="mailto:jzuhone@gmail.com" x-apple-data-detectors="true" x-apple-data-detectors-type="link" x-apple-data-detectors-result="2">jzuhone@gmail.com</a><br><a href="http://www.jzuhone.com/" x-apple-data-detectors="true" x-apple-data-detectors-type="link" x-apple-data-detectors-result="3">http://www.jzuhone.com</a></span><br style="font-family: UICTFontTextStyleBody; -webkit-text-size-adjust: auto;"></div></div></div><div><br>On Mar 31, 2016, at 4:25 PM, Nathan Goldbaum <<a href="mailto:nathan12343@gmail.com">nathan12343@gmail.com</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 31, 2016 at 3:07 PM, Cameron Hummels <span dir="ltr"><<a href="mailto:chummels@gmail.com" target="_blank">chummels@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><br></div><div>If that is what you're suggesting, it seems fine to me, but couldn't we just turn off the `start` argument to solve this problem without your proposed change?</div></div></blockquote><div><br></div></span><div>Since sum is a python builtin, we have no control over it.</div></div></div></div></blockquote><div><br></div></span><div>But I thought you said that the python builtin sum had an *optional* start argument, which defaults to zero.  Isn't it possible to (1) make it not used or (2) default it to the first value of the YTArray?</div><span class=""><font color="#888888"><div><br></div></font></span></div></div></div></blockquote><div><br></div><div>It's optional, but if you don't specify it, `sum` uses 0. See: <a href="https://docs.python.org/2/library/functions.html#sum">https://docs.python.org/2/library/functions.html#sum</a></div><div><br></div><div>We have no control over this, it all happens at the C level in python itself. If you step though the test script I attached in my original e-mail you'll see this for yourself.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class=""><font color="#888888"><div></div><div><br></div><div>Cameron</div></font></span><div><div class="h5"><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="gmail_extra"><br><div class="gmail_quote"><div><div>On Thu, Mar 31, 2016 at 12:39 PM, Nathan Goldbaum <span dir="ltr"><<a href="mailto:nathan12343@gmail.com" target="_blank">nathan12343@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div><div dir="ltr">Hi all,<div><br></div><div>Today a student I am working with ran into an issue illustrated by the following test script:</div><div><br></div><div>    from yt.units import cm</div><div><br></div><div>    arr = [1, 2, 3]*cm</div><div>    sum(arr)</div><div><br></div><div>Right now this errors out with the following traceback:</div><div><br></div><div><a href="http://paste.yt-project.org/show/6378/" target="_blank">http://paste.yt-project.org/show/6378/</a><br></div><div><br></div><div>The reason for this is that the python builtin sum command has an optional `start` argument, which defaults to 0. The error is happening because the first element of the array (1 km) has different units from 0.</div><div><br></div><div>Sum is probably not the best way to do this, but I think erroring out here is an overly harsh user experience, especially for a user who is new to python and might not be aware of the possible performance implications of using sum on a large array.</div><div><br></div><div>Incidentally, an analogous script with astropy quantities does work:</div><div><br></div><div>    from astropy.units import cm</div><div><br></div><div>    arr = [1, 2, 3]*cm</div><div>    sum(arr)</div><div><br></div><div>This is because astropy's quantities let you add zero (and just zero, no other float or integer will work) to an array or quantity with any units.</div><div><br></div><div>On a philosophical level, the difference between 0 cm and 0 is not particular useful in practice, and operationally allowing 0 to be added or subtracted from YTArray instances without erroring out should not have any concrete implications for real programs, since until now it has raised an error. To be honest, I'm now regretting not thinking carefully about this until now....</div><div><br></div><div>Since this is a change to how YTArray, which is fundamental to yt's internals, I wanted to check with the list before proposing a pull request that implements this change.</div><div><br></div><div>Does anyone have any objections?</div><div><br></div><div>Thanks!</div><span><font color="#888888"><div><br></div><div>-Nathan</div></font></span></div>
<br></div></div>_______________________________________________<br>
yt-dev mailing list<br>
<a href="mailto:yt-dev@lists.spacepope.org" target="_blank">yt-dev@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org</a><br>
<br></blockquote></div><span><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div><div dir="ltr"><div>Cameron Hummels<div><span style="font-size:12.8px">NSF Postdoctoral Fellow</span></div><div><span style="font-size:12.8px">Department of Astronomy</span></div><div><span style="font-size:12.8px">California Institute of Technology</span><br></div><div><a href="http://chummels.org" style="font-size:12.8px" target="_blank">http://chummels.org</a><br></div></div></div></div>
</font></span></div>
<br>_______________________________________________<br>
yt-dev mailing list<br>
<a href="mailto:yt-dev@lists.spacepope.org" target="_blank">yt-dev@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org</a><br>
<br></blockquote></div></div></div><br></div></div>
<br>_______________________________________________<br>
yt-dev mailing list<br>
<a href="mailto:yt-dev@lists.spacepope.org" target="_blank">yt-dev@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org</a><br>
<br></blockquote></div></div></div><div><div class="h5"><br><br clear="all"><div><br></div>-- <br><div><div dir="ltr"><div>Cameron Hummels<div><span style="font-size:12.8px">NSF Postdoctoral Fellow</span></div><div><span style="font-size:12.8px">Department of Astronomy</span></div><div><span style="font-size:12.8px">California Institute of Technology</span><br></div><div><a href="http://chummels.org" style="font-size:12.8px" target="_blank">http://chummels.org</a><br></div></div></div></div>
</div></div></div></div>
<br>_______________________________________________<br>
yt-dev mailing list<br>
<a href="mailto:yt-dev@lists.spacepope.org">yt-dev@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org</a><br>
<br></blockquote></div><br></div></div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>yt-dev mailing list</span><br><span><a href="mailto:yt-dev@lists.spacepope.org">yt-dev@lists.spacepope.org</a></span><br><span><a href="http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org">http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org</a></span><br></div></blockquote></body></html>