|
From: | Paul Kienzle |
Subject: | Re: uniform random variable in oct file? |
Date: | Fri, 8 Sep 2006 08:42:10 -0400 |
On Sep 8, 2006, at 6:44 AM, Michael Creel wrote:
I'm wondering what's the most efficient way to get a U(0,1) draw in an .oct file. I'm currently using f_return = feval("rand"); rand_draw = f_return(0).double_value(); This works fine. The Octave Wiki, at http://wiki.octave.org/wiki.pl?CPPQuickReference, suggests octave_rand::distribution("uniform"); octave_rand::matrix(a,b) What are the advantages / disadvantages of the two options?
feval is very expensive --- it needs to do dynamic lookup of the function definition, creating the (null) argument vector, creating the octave double and the return vector to hold it and extracting the double from the octave value. I'm guessing you will have about a 100x speedup by calling rand directly.
The disadvantage is that you get the rand from liboctave rather than the rand installed by the user. Not a problem unless you have e.g., requirements for a safe parallel generator.
- Paul
[Prev in Thread] | Current Thread | [Next in Thread] |