help-octave
[Top][All Lists]
Advanced

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

Re: sparse matrix operations


From: David Bateman
Subject: Re: sparse matrix operations
Date: Wed, 17 Nov 2004 00:01:35 +0100
User-agent: Mutt/1.4.1i

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

-- 
David Bateman                                address@hidden
Motorola CRM                                 +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 1 69 35 77 01 (Fax) 
91193 Gif-Sur-Yvette FRANCE

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary



-------------------------------------------------------------
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]