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: SANDS
Subject: Re: Efficient multiplication by a diagonal matrix
Date: Thu, 14 Nov 1996 21:19:59 -0400 (EDT)

Mario Storti writes:
[stuff deleted]
>But it is equivalent to kron(v,ones(1,m)) and it has the same problems
>of inefficiency as mentioned in the original post:

Not so! In 
B=kron(v,ones(1,m)).*A;
the first factor (kron(v,ones(1,m))) is calculated
by actually carrying out a number of scalar multiplications
in the computer (if you look at the source for kron
you'll see that you have the additional overhead of
performing loops in the high level MATLABish language--
very costly!) However by using "Tony's Trick" the first
factor in
B=v(:,ones(1,m)) .* A;
is determined by simply copying the elements of v into
memory--a potentially *much* faster operation (depending
on your hardware). I'm not sure about how Tony's Trick
is carried out in octave but I'm fairly certain that 
the MATLAB interpreter is smart about how it executes 
such indexing operations. I've never performed actual
tests to compare the two (because I never thought of
using kron to accomplish this operation) so I can't 
say with absolute certainty which is faster. 

Scott Sands


reply via email to

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