<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Automatic array growth gets a lot faster in R2011a</title>
	<atom:link href="http://blogs.mathworks.com/steve/2011/05/16/automatic-array-growth-gets-a-lot-faster-in-r2011a/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/steve/2011/05/16/automatic-array-growth-gets-a-lot-faster-in-r2011a/</link>
	<description>Steve Eddins manages the Image &#38; Geospatial development team at The MathWorks and coauthored Digital Image Processing Using MATLAB. He writes here about image processing concepts, algorithm implementations, and MATLAB.</description>
	<lastBuildDate>Wed, 22 May 2013 10:54:29 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
	<item>
		<title>By: João Henriques</title>
		<link>http://blogs.mathworks.com/steve/2011/05/16/automatic-array-growth-gets-a-lot-faster-in-r2011a/#comment-24221</link>
		<dc:creator>João Henriques</dc:creator>
		<pubDate>Wed, 18 May 2011 19:16:05 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/steve/2011/05/16/automatic-array-growth-gets-a-lot-faster-in-r2011a/#comment-24221</guid>
		<description><![CDATA[This is great, there are always instances where the output size is unknown, for example the foobar function there could return a variable number of elements.

The trick I&#039;ve used so far (and with great results, I might say) is to store results in a cell array and defer concatenation until after the loop.

&lt;pre&gt;
y = cell(1, n);
for k = 1:n
    y{k} = foobar(k);
end
y = cat(1, y{:});
&lt;/pre&gt;

It still doesn&#039;t help in the extreme case of a WHILE loop where you can&#039;t guess the maximum number of iterations.]]></description>
		<content:encoded><![CDATA[<p>This is great, there are always instances where the output size is unknown, for example the foobar function there could return a variable number of elements.</p>
<p>The trick I&#8217;ve used so far (and with great results, I might say) is to store results in a cell array and defer concatenation until after the loop.</p>
<pre>
y = cell(1, n);
for k = 1:n
    y{k} = foobar(k);
end
y = cat(1, y{:});
</pre>
<p>It still doesn&#8217;t help in the extreme case of a WHILE loop where you can&#8217;t guess the maximum number of iterations.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://blogs.mathworks.com/steve/2011/05/16/automatic-array-growth-gets-a-lot-faster-in-r2011a/#comment-24219</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Wed, 18 May 2011 16:12:02 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/steve/2011/05/16/automatic-array-growth-gets-a-lot-faster-in-r2011a/#comment-24219</guid>
		<description><![CDATA[Oliver&#8212;I don&#039;t know anything about that.]]></description>
		<content:encoded><![CDATA[<p>Oliver&mdash;I don&#8217;t know anything about that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Oliver Woodford</title>
		<link>http://blogs.mathworks.com/steve/2011/05/16/automatic-array-growth-gets-a-lot-faster-in-r2011a/#comment-24218</link>
		<dc:creator>Oliver Woodford</dc:creator>
		<pubDate>Wed, 18 May 2011 15:56:17 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/steve/2011/05/16/automatic-array-growth-gets-a-lot-faster-in-r2011a/#comment-24218</guid>
		<description><![CDATA[Great! I once noticed that setting values in a sparse array to zero, one by one, in a loop is very slow. Has this been fixed? (I haven&#039;t yet upgraded to test it myself).]]></description>
		<content:encoded><![CDATA[<p>Great! I once noticed that setting values in a sparse array to zero, one by one, in a loop is very slow. Has this been fixed? (I haven&#8217;t yet upgraded to test it myself).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ben</title>
		<link>http://blogs.mathworks.com/steve/2011/05/16/automatic-array-growth-gets-a-lot-faster-in-r2011a/#comment-24217</link>
		<dc:creator>Ben</dc:creator>
		<pubDate>Wed, 18 May 2011 06:22:31 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/steve/2011/05/16/automatic-array-growth-gets-a-lot-faster-in-r2011a/#comment-24217</guid>
		<description><![CDATA[It&#039;s great to see this feature added, and long overdue.  There are plenty of problems where it&#039;s difficult or impossible to calculate the array size beforehand, especially combinatoric optimization problems such as tree searches.  The solution there is of course to use size doubling but this new feature will save the hassle.]]></description>
		<content:encoded><![CDATA[<p>It&#8217;s great to see this feature added, and long overdue.  There are plenty of problems where it&#8217;s difficult or impossible to calculate the array size beforehand, especially combinatoric optimization problems such as tree searches.  The solution there is of course to use size doubling but this new feature will save the hassle.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://blogs.mathworks.com/steve/2011/05/16/automatic-array-growth-gets-a-lot-faster-in-r2011a/#comment-24215</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Tue, 17 May 2011 18:28:21 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/steve/2011/05/16/automatic-array-growth-gets-a-lot-faster-in-r2011a/#comment-24215</guid>
		<description><![CDATA[Tom&#8212;I agree. I have been annoyed that the C++ vector class handled this sort of thing better than previous versions of MATLAB.]]></description>
		<content:encoded><![CDATA[<p>Tom&mdash;I agree. I have been annoyed that the C++ vector class handled this sort of thing better than previous versions of MATLAB.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tom</title>
		<link>http://blogs.mathworks.com/steve/2011/05/16/automatic-array-growth-gets-a-lot-faster-in-r2011a/#comment-24214</link>
		<dc:creator>tom</dc:creator>
		<pubDate>Tue, 17 May 2011 18:25:03 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/steve/2011/05/16/automatic-array-growth-gets-a-lot-faster-in-r2011a/#comment-24214</guid>
		<description><![CDATA[This is something that allocators in the C++ STL have done for approximately forever. I&#039;m glad to see that MATLAB now has a reasonable allocation strategy.]]></description>
		<content:encoded><![CDATA[<p>This is something that allocators in the C++ STL have done for approximately forever. I&#8217;m glad to see that MATLAB now has a reasonable allocation strategy.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://blogs.mathworks.com/steve/2011/05/16/automatic-array-growth-gets-a-lot-faster-in-r2011a/#comment-24213</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Tue, 17 May 2011 12:49:54 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/steve/2011/05/16/automatic-array-growth-gets-a-lot-faster-in-r2011a/#comment-24213</guid>
		<description><![CDATA[Wes and Julian&#8212;I will try to post additional details later this week.

Gary&#8212;I completely disagree. When you don&#039;t know the the size of the array at the beginning of the loop, it can be extremely cumbersome to implement automatic array growth yourself in order to make the implementation scalable. I know this because I&#039;ve had to do it many times.  Now I simply don&#039;t have to worry about it because MATLAB is an even better array-oriented language than it already was.

Not preallocating was regarded as a poor coding practice because MATLAB didn&#039;t handle it well. Now MATLAB handles it well.

Also, the feature works for array growth by repeated concatenation, something I didn&#039;t mention in the post.]]></description>
		<content:encoded><![CDATA[<p>Wes and Julian&mdash;I will try to post additional details later this week.</p>
<p>Gary&mdash;I completely disagree. When you don&#8217;t know the the size of the array at the beginning of the loop, it can be extremely cumbersome to implement automatic array growth yourself in order to make the implementation scalable. I know this because I&#8217;ve had to do it many times.  Now I simply don&#8217;t have to worry about it because MATLAB is an even better array-oriented language than it already was.</p>
<p>Not preallocating was regarded as a poor coding practice because MATLAB didn&#8217;t handle it well. Now MATLAB handles it well.</p>
<p>Also, the feature works for array growth by repeated concatenation, something I didn&#8217;t mention in the post.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gary</title>
		<link>http://blogs.mathworks.com/steve/2011/05/16/automatic-array-growth-gets-a-lot-faster-in-r2011a/#comment-24211</link>
		<dc:creator>Gary</dc:creator>
		<pubDate>Tue, 17 May 2011 12:31:52 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/steve/2011/05/16/automatic-array-growth-gets-a-lot-faster-in-r2011a/#comment-24211</guid>
		<description><![CDATA[1000x faster is quite an achievement!  Unfortunately, part of me can&#039;t shake the feeling that it&#039;s a lot of effort to expend to improve MATLAB support of what&#039;s essentially poor coding practice.]]></description>
		<content:encoded><![CDATA[<p>1000x faster is quite an achievement!  Unfortunately, part of me can&#8217;t shake the feeling that it&#8217;s a lot of effort to expend to improve MATLAB support of what&#8217;s essentially poor coding practice.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Julian</title>
		<link>http://blogs.mathworks.com/steve/2011/05/16/automatic-array-growth-gets-a-lot-faster-in-r2011a/#comment-24207</link>
		<dc:creator>Julian</dc:creator>
		<pubDate>Tue, 17 May 2011 10:08:48 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/steve/2011/05/16/automatic-array-growth-gets-a-lot-faster-in-r2011a/#comment-24207</guid>
		<description><![CDATA[Thanks Steve, interesting post. 

One question always struck me is about pre-allocation of cell arrays. Mlint pointed out that my loop might be growing on each iteration, but when the variable in question is a cell array that holds heterogeneous data, I wondered how sizing it in advance really helped without knowing the size of the data to be put in the cells!

Julian.]]></description>
		<content:encoded><![CDATA[<p>Thanks Steve, interesting post. </p>
<p>One question always struck me is about pre-allocation of cell arrays. Mlint pointed out that my loop might be growing on each iteration, but when the variable in question is a cell array that holds heterogeneous data, I wondered how sizing it in advance really helped without knowing the size of the data to be put in the cells!</p>
<p>Julian.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wes</title>
		<link>http://blogs.mathworks.com/steve/2011/05/16/automatic-array-growth-gets-a-lot-faster-in-r2011a/#comment-24206</link>
		<dc:creator>Wes</dc:creator>
		<pubDate>Tue, 17 May 2011 02:58:52 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/steve/2011/05/16/automatic-array-growth-gets-a-lot-faster-in-r2011a/#comment-24206</guid>
		<description><![CDATA[Hi Steve

Thanks for the post. I have a few questions:

- Does this feature work for cell arrays too?

- Is it tied to for loops, or can this behaviour be triggered anywhere an array is growing?

- Presumably this features works under the hood by growing the actual array in memory by more than 1 element at a time (such as doubling the allocated size each time it runs out of space). This means that upon finishing the loop, the memory allocated for the array will be usually be larger than necessary. Does this allocation automatically get &#039;trimmed&#039; to the actual length once the loop finishes, or at any other time? Or do we potentially have the situation where an array has 2^25+1 elments but it keeps a 2^26 element allocation size?]]></description>
		<content:encoded><![CDATA[<p>Hi Steve</p>
<p>Thanks for the post. I have a few questions:</p>
<p>- Does this feature work for cell arrays too?</p>
<p>- Is it tied to for loops, or can this behaviour be triggered anywhere an array is growing?</p>
<p>- Presumably this features works under the hood by growing the actual array in memory by more than 1 element at a time (such as doubling the allocated size each time it runs out of space). This means that upon finishing the loop, the memory allocated for the array will be usually be larger than necessary. Does this allocation automatically get &#8216;trimmed&#8217; to the actual length once the loop finishes, or at any other time? Or do we potentially have the situation where an array has 2^25+1 elments but it keeps a 2^26 element allocation size?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
