help-octave
[Top][All Lists]
Advanced

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

Re: help requested with extremely slow for loop?


From: Jaroslav Hajek
Subject: Re: help requested with extremely slow for loop?
Date: Wed, 24 Mar 2010 18:18:18 +0100

On Wed, Mar 24, 2010 at 2:36 PM, Carlo de Falco <address@hidden> wrote:
>
> On 24 Mar 2010, at 11:22, Joachim De Beule wrote:
>
>>       octave> idxs = find(x & y);
>>       octace>
>>       tic
>>       for j = idxs
>>               x(y(j)) += x(j);
>>               x(j) = 0;
>>       endfor
>>       toc
>>
>>       octave> Elapsed time is 15.96 seconds.
>>
>> Does anybody have an idea what is going on here or have suggestions
>> about how
>> to do this differently? Basically, y(j) holds the new j' that should
>> get the
>> value of x(j), after which x(j) itself needs to be set to zero...
>
> what about the following?
>
> idxs = find (x & y);
> x(y(idxs)) += x(idxs);
> x(idxs)=0;
>

This should work well unless there are loop-carried dependencies
assumed, in which case you'll need something more elaborate. I should
add that using sparse row vectors is not the best idea; Octave uses a
compressed column format for sparse matrices so a sparse row vector is
not actually compressed at all (i.e. needs O(N) storage, where N is
the length).

If you have thousands of independent vectors, you may also consider
stacking them in a matrix.

-- 
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz



reply via email to

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