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: Francesco Potortì
Subject: Re: help requested with extremely slow for loop?
Date: Wed, 24 Mar 2010 18:33:02 +0100

>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).

Wow!  So if you want a sparse vector, it should be a column vector.
An in fact I got this:

octave>         tic
        for j = idxs
                x(y(j)) += x(j);
                x(j) = 0;
        endfor
        toc
octave> > > > octave> Elapsed time is 8.4 seconds.

octave> whos
Variables in the current scope:

  Attr Name         Size                     Bytes  Class
  ==== ====         ====                     =====  ===== 
       ans          1x2                         16  double
       idxs         1x37                       296  double
       j            1x1                          8  double
       x            1x15071213            60287148  double
       y            1x15071213            91006944  double

octave> x=sparse(x');
octave> y=sparse(y');
octave> whos
Variables in the current scope:

  Attr Name           Size                     Bytes  Class
  ==== ====           ====                     =====  ===== 
       ans            1x1                          8  double
       idxs           1x37                       296  double
       x       15071213x1                       2732  double
       y       15071213x1                   30722096  double

octave>         tic
        for j = idxs
                x(y(j)) += x(j);
                x(j) = 0;
        endfor
        toc
octave> > > > octave> Elapsed time is 0.31 seconds.

-- 
Francesco Potortì (ricercatore)        Voice: +39 050 315 3058 (op.2111)
ISTI - Area della ricerca CNR          Fax:   +39 050 315 2040
via G. Moruzzi 1, I-56124 Pisa         Email: address@hidden
(entrance 20, 1st floor, room C71)     Web:   http://fly.isti.cnr.it/


reply via email to

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