[Numpy-discussion] Revised NEP-18, __array_function__ protocol

Robert Kern robert.kern at gmail.com
Sat Jun 30 22:23:48 EDT 2018

On Sat, Jun 30, 2018 at 12:14 PM Stephan Hoyer <shoyer at gmail.com> wrote:

> I’d love to see a generic way of doing random number generation, but I
> agree with Martin that I don’t see it fitting a naturally into this NEP. An
> invasive change to add an array_reference argument to a bunch of functions
> might indeed be worthy of its own NEP, but again I’m not convinced that’s
> actually the right approach. I’d rather add a few new functions like
> random_like, which is a small enough change that concensus on the list
> might be enough.

random_like() seems very weird to me. It doesn't seem like a function that
anyone actually wants. It seems like what people actually want is to be
able to draw random numbers from any distribution as a specified array-like
type and shape, not just sample U(0, 1) with the shape of an existing array.

The most workable way to do this is to modify RandomGenerator (i.e. the new
RandomState design)[1] to accept the array-like type in the class
constructor, and modify its internals to do the right thing. Because the
intrusion on the API is so small, that doesn't require a NEP, just a PR (a
long, complicated, and tedious PR, to be sure)[2]. There are a bunch of
technical issues (if you want to avoid memory copies) because the Cython
implementation requires direct memory access, but that's intrinsic to any
solution to this problem, regardless of the API choices. random_like()
would have the same issues.

[1] https://github.com/bashtage/randomgen
[2] Sorry, Kevin.

Robert Kern
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20180630/fe1c05d5/attachment.html>

More information about the NumPy-Discussion mailing list