[Numpy-discussion] speed of random number generator compared to Julia
njs at pobox.com
Mon Apr 3 12:33:13 EDT 2017
On Apr 3, 2017 8:59 AM, "Pierre Haessig" <pierre.haessig at crans.org> wrote:
Le 03/04/2017 à 15:44, Jaime Fernández del Río a écrit :
that Julia uses this library
<http://www.math.sci.hiroshima-u.ac.jp/%7Em-mat/MT/SFMT/#dSFMT>, which is
different from the home brewed version of the Mersenne twister in NumPy.
The second link I posted claims their speed comes from generating double
precision numbers directly, rather than generating random bytes that have
to be converted to doubles, as is the case of NumPy through this magical
They also throw the SIMD acronym around, which likely means their random
number generation is parallelized.
My guess is that most of the speed-up comes from the SIMD parallelization:
the Mersenne algorithm does a lot of work
produce 32 random bits, so that likely dominates over a couple of
arithmetic operations, even if divisions are involved.
Thanks for the feedback.
I'm not good in enough in reading Julia to be 100% sure, but I feel like
that the random.jl (https://github.com/JuliaLang/
julia/blob/master/base/random.jl) contains a Julia implementation of
Mersenne Twister... but I have no idea whether it is the "fancy" SIMD
version or the "old" 32bits version.
That code contains many references to "dSFMT", which is the name of the
"fancy" algorithm. IIUC dSFMT is related to the mersenne twister but is
actually a different generator altogether -- advertising that Julia uses
the mersenne twister is somewhat misleading IMHO. Of course this is really
the fault of the algorithm's designers for creating multiple algorithms
that have "mersenne twister" as part of their names...
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion