From help-octave-request at bevo dot che dot wisc dot edu Sat Dec 4 22:07:42 1999 Subject: Re: Dot product (nx1).*(nxm) From: Mike Miller To: Andre Bonfrer cc: help-octave at bevo dot che dot wisc dot edu Date: Sat, 4 Dec 1999 22:07:33 -0600 (CST) On Sun, 5 Dec 1999, Andre Bonfrer wrote: > I'm trying to minimise a function that requires a lot of dot products of > the > form (dimensions) > (nx1).*(nxm) > e.g. p .* v > where > p is size nx1 > v is size nxm > > Right now I'm using kron(p,ones(1,m)).*v but it's very slow. Outer product is faster. Use this: (p*ones(1,m)).*v Here's proof: -------------------------------------------------------------------------- GNU Octave, version 2.0.14 (sparc-sun-solaris2.6). Copyright (C) 1996, 1997, 1998, 1999 John W. Eaton. This is free software with ABSOLUTELY NO WARRANTY. For details, type `warranty'. octave:1> p=rand(100,1); octave:2> q=ones(1,50); octave:3> p2=p*q; octave:4> t0=cputime; for i=1:1000, p2=p*q; end , cputime-t0 ans = 2.4600 octave:5> t0=cputime; for i=1:1000, p2=kron(p,q); end , cputime-t0 ans = 188.48 -------------------------------------------------------------------------- So kron is super slow and outer product is about 77 times faster in this case. Regards, Mike -- Michael B. Miller University of Missouri--Columbia http://taxa.psyc.missouri.edu/~mbmiller/ ----------------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.che.wisc.edu/octave/octave.html How to fund new projects: http://www.che.wisc.edu/octave/funding.html Subscription information: http://www.che.wisc.edu/octave/archive.html -----------------------------------------------------------------------