[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: NxN random matrix much cheaper than N^2 random scalars
From: |
Andreas Weber |
Subject: |
Re: NxN random matrix much cheaper than N^2 random scalars |
Date: |
Mon, 17 Nov 2014 19:11:47 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.2.0 |
Hi Daniel,
Am 17.11.2014 um 16:55 schrieb Daniel Molina García:
> I am using GNU Octave, version 3.8.1. I found that generating a matrix,
> for example as
>
> for i=1:1
> normrnd(0, 1, [n, 1]);
> endfor
>
> is much fast than
>
> for i=1:n
> normrnd(0, 1);
> endfor
>
> Why?
Because for loops are slow in octave. JIT would help in the future but
it's still experimental.
In the first case the for-loop is executed only once, therefore you get
only a small runtime penalty. Try to avoid large (high number of runs)
loops whenever possible.
See also this msg:
http://octave.1599824.n4.nabble.com/slow-for-loops-td1609594.html
> By the way, I found that specifying the 2 dimensions with a vector (as
> in the above example) instead of using two parameters is quicker.
How have you exactly measured this?
-- Andy