help-octave
[Top][All Lists]
Advanced

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

Re: help with vectorizing a for loop


From: Martin Helm
Subject: Re: help with vectorizing a for loop
Date: Wed, 05 Oct 2011 01:06:24 +0200

Am Dienstag, den 04.10.2011, 23:47 +0200 schrieb Martin Helm: 
> Am Dienstag, den 04.10.2011, 11:20 -1000 schrieb Rick T:
> > Sorry about that t_rebuilt should be t.
> > 
> It's a bit late here so I hope I did not completely mess this up now
> 
> aa_sig_combined=sum(diag(inner_freq(1:end-1,2))*cos(2.*pi.*inner_freq(1:end-1,1)*t).+
>  repmat(inner_freq(1:end-1,3),[1 length(t)]));
> 
> takes roughly 77 seconds on my netbook but memory consumption goes up to
> about 3 gig for the octave process (so it uses swap here, not sure what
> happens on windows).
> 
> 
I thought again about that and excessive use of memory can be avoide by 
splitting the calculation into some chunks

# just as example use random values
t=rand(1,15679);
inner_freq=rand(8193,3);

N=4; # use 4 chunks
nn = int32(linspace(1, length(t)+1, N+1))
aa_sig_combined=zeros(size(t));
for ii=1:N
  tic;
  ind = nn(ii):nn(ii+1)-1;
  aa_sig_combined(ind) = ...
    sum(diag(inner_freq(1:end-1,2)) * ...
        cos(2 .* pi .* inner_freq(1:end-1,1) * t(ind)) ...
        .+ repmat(inner_freq(1:end-1,3),[1 length(ind)]));
  toc
endfor

which gives 
nn =

      1   3921   7841  11760  15680

Elapsed time is 6.94054 seconds.
Elapsed time is 6.94747 seconds.
Elapsed time is 7.04162 seconds.
Elapsed time is 6.94685 seconds.

so a total time of about 28 sec.





reply via email to

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