octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: randn benchmarks


From: Paul Kienzle
Subject: Re: randn benchmarks
Date: Sat, 24 Jan 2004 19:24:36 -0500


On Jan 24, 2004, at 3:32 PM, Paul Kienzle wrote:

Comparing apples to apples (randmt to rand instead
of randn), I find that octave-forge's rand is faster on
both IRIX and Linux.  I can squeeze another 25% out
of it by directly accessing the array values.  I will need
to do this anyway for N-d array support.  I will post this
code in a bit (it is on another machine which just stopped
responding).

The attached code uses the randn generator suggested
earlier by David (not the ziggurat algorithm):

  while(1) {
    const double u = randu();
    const double v = 1.7156 * (randu() - 0.5);
    const double x = u - 0.449871;
    const double y = fabs(v) + 0.386595;
    const double q = x*x + y*(0.196*y - 0.25472*x);
    if (q < 0.27597) return v/u;
    if ((q <= 0.27846) && (v*v < - 4. * log(u) *u*u)) return v/u;
  }

Anyone know if the constants are valid for doubles?  They
should be if I understand the algorithm (although there may
be a slight loss in efficiency over the ideal constants).

The time for rand(1000) on my machine is now 0.17 rather
than 0.25, and randn(1000) is 0.60 rather than 2.5.

It also creates n-d arrays.

It is not well tested.

I should also take the opportunity to add in the fast
poisson generator that I have, but that will have to
wait until next pass.

Paul Kienzle
address@hidden

Attachment: rand.cc
Description: Binary data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]