help-octave
[Top][All Lists]
Advanced

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

Re: Efficient multiplication by a diagonal matrix


From: John W. Eaton
Subject: Re: Efficient multiplication by a diagonal matrix
Date: Thu, 14 Nov 1996 21:37:57 -0600

On 14-Nov-1996, address@hidden <address@hidden> wrote:

: B=kron(v,ones(1,m)).*A;

Yes, kron will definitely be slow because it uses interpreted loops.

: B=v(:,ones(1,m)) .* A;

This will be fairly fast.  In the test I ran, with v = rand (1000,1)
and m = 10, it was nearly 600 times faster than kron.  For some cases
though,

  v * ones(1,m) .* A

will actually be faster, at least in Octave.

If the .* operator is overloaded to do the job of row and column
scaling, then I would expect that

  v .* A

will be faster than any of the other methods.  It will also use less
memory, which might turn out to be important if length(v) columns(A)
are both large.  It might even be easier to read, too.

So, why am I writing this instead of implementing that?  :-)

jwe


reply via email to

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