<div dir="ltr">Thoughts on basing this on a more generic Array type rather than the np.ndarray?  I can imagine other nd-array libraries (XArray, Tensorflow, Dask.array) wanting to reuse this work.  For dask.array in particular we would want to copy this entirely, but we probably can't specify that dask.arrays are np.ndarrays.  It would be nice to ensure that the container type was swappable.</div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Nov 25, 2017 at 6:31 PM, Matthew Rocklin <span dir="ltr"><<a href="mailto:mrocklin@gmail.com" target="_blank">mrocklin@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"><span class=""><blockquote type="cite" style="font-family:-apple-system,BlinkMacSystemFont,sans-serif;font-size:14px;margin:5px;padding-left:10px;border-left:thin solid rgb(26,188,156)"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">Can you make a case for the usefulness numpy annotations? What benefits to you want to achieve and how will annotation aid in getting there.</div></div></div></blockquote></span><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><ol><li>Error checking on large codebases with systems like MyPy</li><li>Hinting and error checking at code-writing time with systems like Jedi "Hey, this function expects a 2-d square array but you just passed in a 3d array with irregular sizes"</li><li>Supporting systems like the Cython compiler with type information, allowing them to speedup pure-python code without switching to the Cython language</li></ol><div><br></div></div></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Sat, Nov 25, 2017 at 6:12 PM, Stephan Hoyer <span dir="ltr"><<a href="mailto:shoyer@gmail.com" target="_blank">shoyer@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Sat, Nov 25, 2017 at 7:21 AM Marten van Kerkwijk <<a href="mailto:m.h.vankerkwijk@gmail.com" target="_blank">m.h.vankerkwijk@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">A question of perhaps broader scope than what you were asking for, and<br>
more out of curiosity than anything else, but can one mix type<br>
annotations with others? E.g., in astropy, we have a decorator that<br>
looks for units in the annotations (not dissimilar from dtype, I<br>
guess). Could one mix annotations or does one have to stick with one<br>
purpose?<br></blockquote><div><br></div><div>Hi Marten,</div><div><br></div><div>I took a look at Astropy's units decorator:</div><div><a href="http://docs.astropy.org/en/stable/api/astropy.units.quantity_input.html" target="_blank">http://docs.astropy.org/en/sta<wbr>ble/api/astropy.units.quantity<wbr>_input.html</a></div><div><br></div><div>Annotations for return values that "coerce" units would be hard to make compatible with typing, because type annotations are used to check programs, not change runtime semantics. But in principle, I think you could even make a physical units library that relies entirely on static type checking for correctness, imposing almost no run-time overhead at all. There are several examples for Haskell:<br></div><div><a href="https://wiki.haskell.org/Physical_units" target="_blank">https://wiki.haskell.org/Physi<wbr>cal_units</a><br></div><div><br></div><div>I don't see any obvious way to support to mixing of annotations for typing and runtime effects in the same function, though doing so in the same program might be possible. My guess is that the preferred way to do this would be to use decorators for runtime changes to arguments, and keep annotations for typing. The Python community seems to be standardizing on using annotations for typing:</div><div><a href="https://www.python.org/dev/peps/pep-0563/#non-typing-usage-of-annotations" target="_blank">https://www.python.org/dev/pep<wbr>s/pep-0563/#non-typing-usage-<wbr>of-annotations</a><br></div><div><br></div><div>Cheers,</div><div>Stephan</div></div></div>
<br></div></div><span class="">______________________________<wbr>_________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@python.org" target="_blank">NumPy-Discussion@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/listinfo/numpy-discussion</a><br>
<br></span></blockquote></div><br></div>
</blockquote></div><br></div>