[Numpy-discussion] Interface for wrapping random distribution functions (__array_function__, __ufunc__, ?)

Robert Kern robert.kern at gmail.com
Wed Jun 30 15:48:20 EDT 2021

On Wed, Jun 30, 2021 at 3:34 PM Yoann Mocquin <mocquin at me.com> wrote:

> Hello there,
> here is a feature request for the possibility to wrap numpy random
> distributions to be wrapped by a mechanism like __array_function__ or
> __array_ufunc__. You can find the GH issue at :
> https://github.com/numpy/numpy/issues/19382.
> This post follows [this one](https://github.com/numpy/numpy/issues/18902).
> I figured I should open another issue for `np.random.normal`, but this
> applies for all distributions I guess.
> ## Feature
> Basicaly, I would like that `numpy.random.*` distributions could trigger
> an interface when passed instances from custom classes, "à la"
> `__array_ufunc__` or `__array_function__`. Here is an example concept :

 The main problem is that these are not functions but methods on a hidden
global `RandomState` instance. I haven't kept up fully with all of the
efforts in the `__array_*__` proposals, but I do see that methods are
explicitly excluded from the `__array_function__` mechanism:


The `RandomState` functionality (and thus all of these aliases in
`numpy.random`) are now frozen in functionality (per NEP 19), so we will
not be adding this functionality to them. If the `__array_function__`
developments eventually work out a good way to wrap methods, then we can
think about using that on `Generator`, but I suspect that will not be

Robert Kern
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/numpy-discussion/attachments/20210630/abc93923/attachment-0001.html>

More information about the NumPy-Discussion mailing list