octave-maintainers
[Top][All Lists]
Advanced

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

RE: unvech function for possible inclusion in Octave


From: Hall, Benjamin
Subject: RE: unvech function for possible inclusion in Octave
Date: Fri, 7 Jul 2006 08:55:46 -0400

Since we're discussing vectorization v. loops...I think we can replace

>       x = zeros(g,g);
> 
>       # fill in the symmetric matrix
>       k = 1;
>       for i = 1:g
>               for j = i:g
>                       x(i,j) = v(k);
>                       if (i != j) x(j,i) = v(k); endif
>                       k = k + 1;
>               endfor
>       endfor

with

        ii = repmat( 1:g, [g 1] );
        idx= find( ii <= ii' );
        
        x(idx) = v
        x = x + x' - diag(diag(x))


This might be a case where the vectorization is obscuring what's happening
-- but the speedup is big enough even for moderately sized matrices that is
probably worth it.  Plus, you can leave the original for-loop code commented
out close by to help eliminate any confusion.


reply via email to

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