[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Few questions (convolutions, 'mapping', linspace)
From: |
John Eaton |
Subject: |
Re: Few questions (convolutions, 'mapping', linspace) |
Date: |
Mon, 16 May 94 13:30:01 EDT |
address@hidden (Przemek Klosowski) wrote:
: - I noticed that the linspace operator is fairly slow:
: linspace(-1,1, 10000) takes 25 seconds on a 150MHz r4400, while
: the a=(0:.0001:1); is very quick, and the FFT of the resulting
: matrix is only few seconds. What is the advantage of linspace
: over the range operator, and why is it so slow?
The range operator is built-in, and in Octave it creates a special
range object that only contains the base, limit, and increment, so it
requires the same amount of work and storage to say
1:3:5
or
1:0.1:1e6
The linspace function is currently implemented as an external
function, and creates a matrix with a for loop:
delta = (x2 - x1) / (npoints - 1);
retval = zeros (1, npoints);
for i = 0:npoints-1
retval (i+1) = x1 + i * delta;
endfor
which is terribly inefficient. Changing it to
delta = (x2 - x1) / (npoints - 1);
retval = x1:delta:x2;
should not change the result and will speed things up considerably.
With this change, about the only advantage of the linspace function is
that you don't have to compute the increment yourself.
BTW, the loop in logspace() should probably also be replaced with
retval = 10 .^ retval;
Thanks for pointing this out.
jwe
- Few questions (convolutions, 'mapping', linspace), Przemek Klosowski, 1994/05/16
- Re: Few questions (convolutions, 'mapping', linspace),
John Eaton <=
- Re: Few questions (convolutions, 'mapping', linspace), John Eaton, 1994/05/16
- Re: Few questions (convolutions, 'mapping', linspace), John Eaton, 1994/05/16