[Numpy-discussion] in place random generation

Charles R Harris charlesr.harris@gmail....
Mon Mar 19 13:34:41 CDT 2007


On 3/19/07, Travis Oliphant <oliphant@ee.byu.edu> wrote:
>
> Mark P. Miller wrote:
>
> >Robert:  Just a thought on this topic:
> >
> >Would it be possible for the Scipy folks to add a new module based
> >solely off your old mtrand code (pre-broadcast)?  I have to say that the
> >mtrand code from numpy 0.9.8 has some excellent advantages over the core
> >python random number generators.
> >
> >This would allow Scipy to have a pure random number generator, whereas
> >numpy could keep its fancier (but slower) array-based random number
> >generators.
> >
> >
>
> I've just added a faster path through the random-number generators for
> scalar parameters to the SVN code tree.
>
> It would be great if those who use this could check to see if
>
> 1) it is correct
> 2) it is indeed faster for scalar parameters


It looks much better from the speed standpoint. Using the dirty benchmark I
used in an earlier post I get

In [5]: t1.timeit(100)
Out[5]: 0.088869810104370117

In [6]: t2.timeit(100)
Out[6]: 0.12822699546813965

whereas before I got

In [22]: t1.timeit(100)
Out[22]: 0.086430072784423828

In [23]: t2.timeit(100)
Out[23]: 4.276231050491333

i.e. about a 33x speedup. Good job! There is probably a bit more to be
gained but I'm not sure it's worth the effort.

Here is a quick test of normal:

In [9]: a = numpy.random.normal(2,3,10000)

In [10]: a.std()
Out[10]: 2.96173131656

In [11]: a.mean()
Out[11]: 2.0158598547

So that's within the expected error.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20070319/38548394/attachment.html 


More information about the Numpy-discussion mailing list