Path: news.mathworks.com!not-for-mail
From: "Richard " <irecycle@shaw.ca>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Vectorization question (newbie alert)
Date: Fri, 17 May 2013 22:27:06 +0000 (UTC)
Organization: Simon Fraser University
Lines: 24
Message-ID: <kn6arq$c35$1@newscl01ah.mathworks.com>
References: <kn697c$7tp$1@newscl01ah.mathworks.com> <kn6ab1$aqg$1@newscl01ah.mathworks.com>
Reply-To: "Richard " <irecycle@shaw.ca>
NNTP-Posting-Host: www-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1368829626 12389 172.30.248.47 (17 May 2013 22:27:06 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 17 May 2013 22:27:06 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 391472
Xref: news.mathworks.com comp.soft-sys.matlab:795755

"James Tursa" wrote in message <kn6ab1$aqg$1@newscl01ah.mathworks.com>...
> "Richard " <irecycle@shaw.ca> wrote in message <kn697c$7tp$1@newscl01ah.mathworks.com>...
> > Until yesterday, I've never used MATLAB (however I've done a fair amount of programming in languages like C/C++, java, etc.).  I'm trying to assist someone with optimizing one of their modules that takes many hours to run.  Using the profiler, I found that one loop was 
[snip]
> > Yea?  Nay?
> > 
> > Am I using the correct multiplication operator in my code?
> 
> Yes, assuming that the first loop above has a f = 0 statement prior to loop entry. The following does the same thing using matrix multiplication. It likely won't be any faster for you but I am just showing you another way:
> 
>    j = 1:20
>    f = nn(i,j) * log(p(j)).'; % The matrix multiply essentially does the sum part
> 
> James Tursa

Thanks much for your response, James.  Much appreciated.

I am amazed at the amount of time saved with vectorization.  Clearly the person that originally coded the module wasn't aware of this.

I'm going to try your matrix multiplication version just for giggles!

Thanks again!

Richard