<div dir="ltr"><div>Hi Hameer,<br><br></div><div>I think the override on `dtype` would work - after all, the override is checked before anything is done, so one can just pass in `self` if one wishes (or some helper class that contains both `self` and any desired further information.<br><br>But, as you note, it would not cover everything, and your `array_reference` idea definitely makes things more uniform. Indeed, it would allow one to implement things like `np.zeros_like` using `np.zero`, which seems quite nice.<br><br></div><div>Still, I'm not sure whether this should be included in the present NEP or is best done separately after, with a few concrete examples of where it would be useful.<br><br></div><div>All the best,<br><br></div><div>Marten<br></div><div><br></div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Jun 30, 2018 at 10:40 AM, Hameer Abbasi <span dir="ltr"><<a href="mailto:einstein.edison@gmail.com" target="_blank">einstein.edison@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><div>Hi Marten,</div><span class=""><br><blockquote class="m_-3172826703519704994hm_quoted_text" style="padding-left:8px;margin:0;border-left:1px solid rgb(185,185,185);color:rgb(100,100,100)">
    <div>Sorry, I had clearly misunderstood. It would indeed be nice for overrides to work on functions like `zeros` or `arange` as well, but it seems strange to change the signature just for that. As a possible alternative, should we perhaps generally check for overrides on `dtype`?</div></blockquote><div><br></div></span><div>While this very clearly makes sense for something like astropy, it has a few drawbacks:</div><div><ul style="font-style:normal;font-variant-caps:normal;font-weight:normal;font-stretch:normal;font-size:15px;line-height:17px;font-family:"Helvetica Neue";text-decoration:none;color:rgb(0,0,0);background-color:rgba(0,0,0,0)"><li>Other duck arrays such as Dask need more information than just the dtype. For example, Dask needs chunk sizes, XArray needs axis labels, and pydata/sparse needs to know the type of the <span style="background-color:rgba(0,0,0,0)">reference array in order to make one of the same type. The information in a reference array is a strict superset of information in the dtype.</span></li><li>There’s a need for a separate protocol, which might be a lot harder to work with for both NumPy and library authors.</li><li>Some things, like numpy.random.RandomState, don’t accept a dtype argument.</li></ul><div>As for your concern about changing the signature, it’s easy enough with a decorator. We’ll need a separate decorator for array generation functions. Something like:</div></div><div><pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'Menlo';font-size:9.0pt"><pre style="font-family:Menlo;font-size:9pt"><span style="color:#cc7832">def </span><span style="color:#ffc66d">array_generation_function</span>(<wbr>func):<br>    <span style="color:#bbb529">@functools.wraps</span>(func)<br>    <span style="color:#cc7832">def </span><span style="color:#ffc66d">wrapped</span>(*args<span style="color:#cc7832">, </span>**kwargs<span style="color:#cc7832">, </span>array_reference=np._NoValue):<br>        <span style="color:#cc7832">if </span>array_reference <span style="color:#cc7832">is not </span>np._NoValue:<br>            success<span style="color:#cc7832">, </span>result = try_array_function_override(<wbr>wrapped<span style="color:#cc7832">, </span>[array_reference]<span style="color:#cc7832">, </span>args<span style="color:#cc7832">, </span>kwargs)<br><br>            <span style="color:#cc7832">if </span>success:<br>                <span style="color:#cc7832">return </span>result<br><br>        <span style="color:#cc7832">return </span>func(*args<span style="color:#cc7832">, </span>**kwargs)<br><br>    <span style="color:#cc7832">return </span>wrapped</pre></pre></div><span class="HOEnZb"><font color="#888888"><div>Hameer Abbasi</div><blockquote class="m_-3172826703519704994hm_quoted_text" style="padding-left:8px;margin:0;border-left:1px solid rgb(185,185,185);color:rgb(100,100,100)">
    

</blockquote>



        

        

        

    

</font></span></div>
<br>______________________________<wbr>_________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@python.org">NumPy-Discussion@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/numpy-<wbr>discussion</a><br>
<br></blockquote></div><br></div>