<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Oct 26, 2016 at 4:30 PM, Pavlyk, Oleksandr <span dir="ltr"><<a href="mailto:oleksandr.pavlyk@intel.com" target="_blank">oleksandr.pavlyk@intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
The module under review, similarly to randomstate package, provides alternative basic pseudo-random number generators (BRNGs), like MT2203, MCG31, MRG32K3A, Wichmann-Hill. The scope of support differ, with randomstate implementing some generators absent in MKL and vice-versa.<br>
<br></blockquote><div><br></div><div>Is there a reason that randomstate shouldn't implement those generators?<br></div><div><br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Thinking about the possibility of providing the functionality of this module within the framework of randomstate, I find that randomstate implements samplers from statistical distributions as functions that take the state of the underlying BRNG, and produce a single variate, e.g.:<br>
<br>
<a href="https://github.com/bashtage/ng-numpy-randomstate/blob/master/randomstate/distributions.c#L23-L26" rel="noreferrer" target="_blank">https://github.com/bashtage/<wbr>ng-numpy-randomstate/blob/<wbr>master/randomstate/<wbr>distributions.c#L23-L26</a><br>
<br>
This design stands in a way of efficient use of MKL, which generates a whole vector of variates at a time. This can be done faster than sampling a variate at a time by using vectorized instructions.  So I wrote mkl_distributions.cpp to provide functions that return a given size vector of sampled variates from each supported distribution.<br></blockquote><div><br>I don't know a huge amount about 
pseudo-random number generators, but this seems superficially to be 
something that would benefit random number generation as a whole 
independently of whether MKL is used.  Might it be possible to modify 
the numpy implementation to support this sort of vectorized approach? <br></div><div><br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Another point already raised by Nathaniel is that for numpy's randomness ideally should provide a way to override default algorithm for sampling from a particular distribution.  For example RandomState object that implements PCG may rely on default acceptance-rejection algorithm for sampling from Gamma, while the RandomState object that provides interface to MKL might want to call into MKL directly.<br></blockquote><div><br></div><div>The approach that pyfftw uses at least for scipy, which may also work here, is that you can monkey-patch the scipy.fftpack module at runtime, replacing it with pyfftw's drop-in replacement.  scipy then proceeds to use pyfftw instead of its built-in fftpack implementation.  Might such an approach work here?  Users can either use this alternative randomstate replacement directly, or they can replace numpy's with it at runtime and numpy will then proceed to use the alternative.  <br></div><div><br></div></div></div></div>