help-octave
[Top][All Lists]
Advanced

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

Re: uniform random variable in oct file?


From: Michael Creel
Subject: Re: uniform random variable in oct file?
Date: Fri, 08 Sep 2006 14:45:35 +0200
User-agent: Thunderbird 1.5.0.5 (X11/20060812)

I'm using this in the samin.cc code. I have switched to the liboctave version. The samin_example.m code (in o-f) took about 6.5 seconds to run on the machine I'm working at, using the old method, and it now takes about 5.25 seconds (timings are inherently random here). So I'm guessing that the fact that the call is made many times, and that caching is working, plus the effect of other overhead, mean that the speedup in this case is not so high as the theoretical speedup for a single call. But it is faster and the code is nicer to read. Thanks, M.

Paul Kienzle wrote:

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



reply via email to

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