Path: news.mathworks.com!not-for-mail
From: "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
Newsgroups: comp.soft-sys.matlab
Subject: Re: finding consecutive numbers (runs)
Date: Thu, 13 Dec 2007 09:53:18 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 36
Message-ID: <fjqvee$5jt$1@fred.mathworks.com>
References: <fjp9pj$p8g$1@fred.mathworks.com> <fjpihi$p2j$1@fred.mathworks.com> <fjplk2$fgm$1@fred.mathworks.com> <fjqfa3$ce4$1@fred.mathworks.com> <fjqkto$9mc$1@fred.mathworks.com>
Reply-To: "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1197539598 5757 172.30.248.37 (13 Dec 2007 09:53:18 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 13 Dec 2007 09:53:18 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:442301


"William Dampier" <walldo2@gmail.com> wrote in message <fjqkto$9mc
$1@fred.mathworks.com>...
> ........
> The 'reshape' statement is the only bottleneck.  I separated
> out the cumsum statement just to check which was the
> offending statement.
> .......
------------
  Will, I am surprised that you found the three 'reshape' instructions to be 
significant bottlenecks.  As I understand it, this instruction by itself does not 
require any relative location shifts or alterations in memory, but rather an 
altered element-indexing scheme that ought to be comparatively rapid.

  In the case of the first 'reshape', I would think that computing the array, 
[zeros(1,m);x.'], would have been much the greater computational task.  This 
requires first, a transpose of x involving as it does a complete rearrangement 
in memory, and then followed by an expansion of it by inserting m zeros at 
equally-spaced intervals throughout its length which means further extensive 
displacements.  Perhaps I ought to have written the equivalent expression, 
[zeros(m,1),x].', instead, which would allow inserting the m zeros in one 
contiguous initial block in memory and then transposing it all afterwards.  
(You might try that.)  Of course, I am only guessing as to the coding tricks 
used by MathWorks' programmers.

  For the second two reshapes it seems to me the final transpose in each case 
would cause the greatest delay, again because of the necessary 
rearrangement in relative memory locations.  The cumsums in each do not 
involve rearrangement but simply a cumulative serial addition of successive 
elements, which ought to be relatively fast with no fancy indexing schemes 
involved.

  I am afraid I cannot claim to be an expert on matlab's underlying array 
manipulation algorithms, however, since my own matlab system is seriously 
outdated (v4a - 1994.)

Roger Stafford