help-octave
[Top][All Lists]
Advanced

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

Re: sparse matrix operations


From: E. Joshua Rigler
Subject: Re: sparse matrix operations
Date: Tue, 16 Nov 2004 18:47:28 -0700

Thanks!  This worked perfectly, and your technique was consistently
faster than my loop-based technique when I tested it by multiplying two
tri-diagonal banded matrices of increasing size, and recorded the
average time of several passes using tic/toc.  

HOWEVER, if all I intended to do was multiply two similarly banded
matrices together all the time, I could simply use the '*' operator. 
Something closer to what I need this functionality for can be
demonstrated if one fills up the second matrix while keeping the first
matrix banded.  I find that there is a cross-over point in performance
when the matrices are between 1000x1000 and 5000x5000 elements (the
loop-based approach was over 5x faster for the latter), although I also
noted that my kernel was swapping like crazy during these operations, so
the exact performance hit can't be determined until I try rerunning
these tests using cputime().

Nevertheless, these results tell me two related things:  1) your
technique must implicitly allocate more temporary memory than the
loop-based approach, and 2) not insignificant CPU time is being used to
perform this allocation for the larger matrices.

So, again I contemplate translating my .m file into a .oct file, unless
you have some idea why your approach would require more memory than
mine, and if this is something that might be remedied.  Thanks again!

-EJR



On Tue, 2004-11-16 at 16:01, David Bateman wrote:
> Why not generalize what I just sent as 
> 
> function X = sp_multiply(A,B,X_template)
> 
>     if (nargin ~= 3)
>         usage('X = sp_multiply(A,B,X_template)\n');
>     endif
> 
>     if (rows(X_template) ~= rows(A) ||
>         columns(X_template) ~= columns(B))
>         error('Template matrix has wrong dimensions');
>     endif
> 
>     [i,j]=find(X_template);
>     [r,c]=size(X_template);
>     X = sparse(i,j,full(spsum(A(i,:)' .* B(:,j))),r,c);
> 
> endfunction
> 
> 
> If you were using the sparse stuff on bevo, the last line might be
> written as
> 
>      X = sparse(r,c);
>      X(i,j) = spsum(A(i,:)' .* B(:,j));
> 
> and that might save you more memory if A(i,:) or B(j,:) have empty rows
> or columns respectively.
> 
> Cheers
> David



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

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