<?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: In-place Operations on Data</title>
	<atom:link href="http://blogs.mathworks.com/loren/2007/03/22/in-place-operations-on-data/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/loren/2007/03/22/in-place-operations-on-data/</link>
	<description>Loren Shure works on design of the MATLAB language at MathWorks. She writes here about once a week on MATLAB programming and related topics.</description>
	<lastBuildDate>Thu, 16 Feb 2012 04:40:26 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Shankar</title>
		<link>http://blogs.mathworks.com/loren/2007/03/22/in-place-operations-on-data/#comment-32846</link>
		<dc:creator>Shankar</dc:creator>
		<pubDate>Wed, 14 Dec 2011 20:21:39 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/03/14/in-place-operations-on-data/#comment-32846</guid>
		<description>I did try the workaround which you have suggested before. Sadly I will have to teach the clients of my class about these which is not what I want.

But I appreciate that you are willing to consider this. Would be great if this comes as part of Matlab soon.

Also I would like to add more to this since the same improvement needs to be done with field values of structures and cell arrays (copies made in those cases as well, like object properties).</description>
		<content:encoded><![CDATA[<p>I did try the workaround which you have suggested before. Sadly I will have to teach the clients of my class about these which is not what I want.</p>
<p>But I appreciate that you are willing to consider this. Would be great if this comes as part of Matlab soon.</p>
<p>Also I would like to add more to this since the same improvement needs to be done with field values of structures and cell arrays (copies made in those cases as well, like object properties).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren Shure</title>
		<link>http://blogs.mathworks.com/loren/2007/03/22/in-place-operations-on-data/#comment-32833</link>
		<dc:creator>Loren Shure</dc:creator>
		<pubDate>Mon, 12 Dec 2011 10:37:14 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/03/14/in-place-operations-on-data/#comment-32833</guid>
		<description>Shankar-

We will consider this and some related ideas as optimizations in the future.  Thanks for you thoughts.

One less beautiful thing you could do for now is to get the property in a temp variable, set the property to [], make the call and set it back as in:

&lt;pre class=&quot;code&quot;&gt;
  obj = DataWrapper( rand( 2, 3) );
  data = obj.Data; % no copy b/c of copy-on-write
  obj.Data = [];
  data = my_inplace_func( data); 
  obj.Data = data;
&lt;/pre&gt;

--Loren</description>
		<content:encoded><![CDATA[<p>Shankar-</p>
<p>We will consider this and some related ideas as optimizations in the future.  Thanks for you thoughts.</p>
<p>One less beautiful thing you could do for now is to get the property in a temp variable, set the property to [], make the call and set it back as in:</p>
<pre class="code">
  obj = DataWrapper( rand( 2, 3) );
  data = obj.Data; % no copy b/c of copy-on-write
  obj.Data = [];
  data = my_inplace_func( data);
  obj.Data = data;
</pre>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shankar</title>
		<link>http://blogs.mathworks.com/loren/2007/03/22/in-place-operations-on-data/#comment-32822</link>
		<dc:creator>Shankar</dc:creator>
		<pubDate>Thu, 08 Dec 2011 22:14:09 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/03/14/in-place-operations-on-data/#comment-32822</guid>
		<description>Hi Loren,

I understand how the inplace technique works and it works fine given that I work within functions and with variables in Matlab( I checked that it works fine using the secret option of format command :)).

The problem I face( may be I&#039;m failing to understand something) is with achieving the same behaviour with object properties. In my understanding Matlab object properties are no different from normal variables in Matlab&#039;s perspective. If I pass a property of an object to an inplace function there is a copy being made and the operation is not done inplace.

The following is the sample I tried



% DataWrapper.m
classdef DataWrapper &lt; handle
    properties
        Data
    end
    
    methods
        function obj = DataWrapper( data )
            obj.Data = data;
        end
    end
end

% my_inplace_func
function in_data = my_inplace_func( in_data )
  in_data = sin( in_data .* 2 );
end

% my_inplace_test with normal variables. No extra copies
% made. ( The nice case ).
function my_inplace_test()
  data = rand( 2, 3);
  data = my_inplace_func( data);
end

% my_inplace_test with object properties. Extra copy is
% being made here. Would be great if you tell me why so.
function my_inplace_test()
  obj = DataWrapper( rand( 2, 3) );
  obj.Data = my_inplace_func( obj.Data);
end



Or is this a bug or a feature to be implemented in future as part of the JIT?

Would be great if you can share some information on this because I use large data arrays and this problem is really stopping me to move to object oriented programming.</description>
		<content:encoded><![CDATA[<p>Hi Loren,</p>
<p>I understand how the inplace technique works and it works fine given that I work within functions and with variables in Matlab( I checked that it works fine using the secret option of format command :)).</p>
<p>The problem I face( may be I&#8217;m failing to understand something) is with achieving the same behaviour with object properties. In my understanding Matlab object properties are no different from normal variables in Matlab&#8217;s perspective. If I pass a property of an object to an inplace function there is a copy being made and the operation is not done inplace.</p>
<p>The following is the sample I tried</p>
<p>% DataWrapper.m<br />
classdef DataWrapper &lt; handle<br />
    properties<br />
        Data<br />
    end</p>
<p>    methods<br />
        function obj = DataWrapper( data )<br />
            obj.Data = data;<br />
        end<br />
    end<br />
end</p>
<p>% my_inplace_func<br />
function in_data = my_inplace_func( in_data )<br />
  in_data = sin( in_data .* 2 );<br />
end</p>
<p>% my_inplace_test with normal variables. No extra copies<br />
% made. ( The nice case ).<br />
function my_inplace_test()<br />
  data = rand( 2, 3);<br />
  data = my_inplace_func( data);<br />
end</p>
<p>% my_inplace_test with object properties. Extra copy is<br />
% being made here. Would be great if you tell me why so.<br />
function my_inplace_test()<br />
  obj = DataWrapper( rand( 2, 3) );<br />
  obj.Data = my_inplace_func( obj.Data);<br />
end</p>
<p>Or is this a bug or a feature to be implemented in future as part of the JIT?</p>
<p>Would be great if you can share some information on this because I use large data arrays and this problem is really stopping me to move to object oriented programming.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2007/03/22/in-place-operations-on-data/#comment-31801</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Thu, 28 Oct 2010 20:56:46 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/03/14/in-place-operations-on-data/#comment-31801</guid>
		<description>Jiang-Ming-

It&#039;s true you can represent the eigenvalues in a vector, but if you look at the help and how they get used, you often need them in a matrix to do various matrix multiplications and other operations.

--loren</description>
		<content:encoded><![CDATA[<p>Jiang-Ming-</p>
<p>It&#8217;s true you can represent the eigenvalues in a vector, but if you look at the help and how they get used, you often need them in a matrix to do various matrix multiplications and other operations.</p>
<p>&#8211;loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jiang-ming zhang</title>
		<link>http://blogs.mathworks.com/loren/2007/03/22/in-place-operations-on-data/#comment-31799</link>
		<dc:creator>jiang-ming zhang</dc:creator>
		<pubDate>Thu, 28 Oct 2010 20:10:35 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/03/14/in-place-operations-on-data/#comment-31799</guid>
		<description>the stupid thing about memory is like this:

[V,D]=eig(H)

D is a n*n diagonal matrix!

it is absolutely stupid!

D can be a n*1 vector, that would save a lot of memory!</description>
		<content:encoded><![CDATA[<p>the stupid thing about memory is like this:</p>
<p>[V,D]=eig(H)</p>
<p>D is a n*n diagonal matrix!</p>
<p>it is absolutely stupid!</p>
<p>D can be a n*1 vector, that would save a lot of memory!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2007/03/22/in-place-operations-on-data/#comment-30968</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Tue, 12 Jan 2010 13:02:44 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/03/14/in-place-operations-on-data/#comment-30968</guid>
		<description>Cris-

Version does matter, but it only gets better in newer versions.  There was a time when even with the same input and output names, copies were always made.

--Loren</description>
		<content:encoded><![CDATA[<p>Cris-</p>
<p>Version does matter, but it only gets better in newer versions.  There was a time when even with the same input and output names, copies were always made.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cris</title>
		<link>http://blogs.mathworks.com/loren/2007/03/22/in-place-operations-on-data/#comment-30967</link>
		<dc:creator>Cris</dc:creator>
		<pubDate>Tue, 12 Jan 2010 08:24:26 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/03/14/in-place-operations-on-data/#comment-30967</guid>
		<description>Ah, so it&#039;s not because of the version of MATLAB. Excellent, thanks!

I&#039;m running through some functions I use often, making sure the output and input argument names are the same... :)</description>
		<content:encoded><![CDATA[<p>Ah, so it&#8217;s not because of the version of MATLAB. Excellent, thanks!</p>
<p>I&#8217;m running through some functions I use often, making sure the output and input argument names are the same&#8230; :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2007/03/22/in-place-operations-on-data/#comment-30964</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Mon, 11 Jan 2010 13:38:37 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/03/14/in-place-operations-on-data/#comment-30964</guid>
		<description>Cris-

Perhaps you have more memory or swap space than me.  On my machine, I run out of memory at that point.  MATLAB has always had SOME inplace memory optimizations.  They&#039;ve just gotten better and more sophisticated over time.

--Loren</description>
		<content:encoded><![CDATA[<p>Cris-</p>
<p>Perhaps you have more memory or swap space than me.  On my machine, I run out of memory at that point.  MATLAB has always had SOME inplace memory optimizations.  They&#8217;ve just gotten better and more sophisticated over time.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cris</title>
		<link>http://blogs.mathworks.com/loren/2007/03/22/in-place-operations-on-data/#comment-30963</link>
		<dc:creator>Cris</dc:creator>
		<pubDate>Mon, 11 Jan 2010 10:15:02 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/03/14/in-place-operations-on-data/#comment-30963</guid>
		<description>Loren,

I don&#039;t understand why, in inplaceTest, you say &quot;if we changed this next call to assign output to a new LHS, we get an error&quot;. In your example you don&#039;t run y = myfuncIP(x). I seem to be able (R2009b) to do that. It would be awkward if a function that can compute in-place always needs the output argument to be the same as the input argument! The beauty of these in-place functions is that you can just change the variable name of the output argument in your old functions and get a nice speed and memory gain, while keeping perfect backward compatibility. But could this lead to problems in R2007a if the function is called with a different LHS argument?</description>
		<content:encoded><![CDATA[<p>Loren,</p>
<p>I don&#8217;t understand why, in inplaceTest, you say &#8220;if we changed this next call to assign output to a new LHS, we get an error&#8221;. In your example you don&#8217;t run y = myfuncIP(x). I seem to be able (R2009b) to do that. It would be awkward if a function that can compute in-place always needs the output argument to be the same as the input argument! The beauty of these in-place functions is that you can just change the variable name of the output argument in your old functions and get a nice speed and memory gain, while keeping perfect backward compatibility. But could this lead to problems in R2007a if the function is called with a different LHS argument?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2007/03/22/in-place-operations-on-data/#comment-30555</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Thu, 27 Aug 2009 11:56:21 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/2007/03/14/in-place-operations-on-data/#comment-30555</guid>
		<description>Tamas-

I believe the API to do that is not documented or supported so could change in the future.  But it is certainly something you could try.

--Loren</description>
		<content:encoded><![CDATA[<p>Tamas-</p>
<p>I believe the API to do that is not documented or supported so could change in the future.  But it is certainly something you could try.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
</channel>
</rss>

