help-octave
[Top][All Lists]
Advanced

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

Re: Strange run time problem with complex numbers


From: Doug Stewart
Subject: Re: Strange run time problem with complex numbers
Date: Fri, 11 Oct 2019 14:33:34 -0400



On Fri, Oct 11, 2019 at 2:22 PM roland65 <address@hidden> wrote:
Hi there,

here below is a small script that gives me headaches:

close all;
clear all;

tic;

M = 4000;
N = 2 * M;

X = rand(1, M*N) + j*rand(1, M*N);

%X(1 : 2000) = 0;      % Slow
%X(2 : 2000) = 0;      % Fast
%X(1 : 2000) = j;      % Fast
%X(1 : 10000) = 0;     % Fast

Y = zeros(M, N);
for m = 1:M
    Y(m, m:2*m) = X(m : 2*m);   
end

toc;

This script creates a big vector X of random *complex* numbers. Then some
parts of this vector are copied to a matrix Y, preallocated to zero. The
copy part here is a silly example selected to be simple and is not
significant.

This script runs in ~ 2 s in my Ubuntu 18.04 box with Octave 5.1.0.

Now, comment out the first commented line. This line just sets the 2000
first elements of X to 0. The scripts now runs in ~ 40 s! That's 20 times
slower!

Then, comment the first commented line, uncomment the second. Now, elements
2 to 2000 are set to 0. First element of X is untouched. Run time: ~ 2 s.

Then, comment the first two commented lines, uncomment the third. Elements 1
to 2000 are set to the complex number j. Run time: ~ 2 s.

Same job with the last commented line. Elements 1 to 10000 of X are set to
0. Run time: ~ 2 s.

As you see, these results seem completely silly. I first suspected some bug
in Octave, but MATLAB behaves exactly the same. I tried with both programs
in Windows: same story.

Note that if X is a real vector, there is no such issue. All run times are
nearly the same ~ 1 s. At least, that result is normal.

I guess there is some type conversion issue here, but I can't find any logic
in these results...





--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


I see the same!!!
ubuntu 18.04 and octive 5.1.1 hgid ans = 730af4e7034a
first one
>> test3337771
    Elapsed time is 76.6549 seconds.


second one
>> test3337771
    Elapsed time is 3.5878 seconds.
>>

--
DASCertificate for 206392


reply via email to

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