Pass by reference for compiled functions
- To: mathgroup at smc.vnet.net
 - Subject: [mg114275] Pass by reference for compiled functions
 - From: "Eric Michielssen" <emichiel at eecs.umich.edu>
 - Date: Mon, 29 Nov 2010 06:10:01 -0500 (EST)
 
For noncompiled functions, one can pass arguments "by reference" and then
modify them inside the routine by assigning the function the attribute
HoldAll.
This does not work for compiled functions: it does not appear possible to
modify arguments to compiled functions, even if they are passed as "global
variables". That is, Mathematica responds to
Myfunction = Compile[
{{var1,_Real}},
Module[{}, 
Modify var 1 or var2;
Return[]], {var2,_Real}];
With
Compile::argset: The assignment to var1 is illegal; it is not valid to
assign a value to an argument. >>  And something similar for var2.
HoldAll does not seem to apply here...
This makes it memory-inefficient to modify large arrays in compiled
functions, as one would have to operate on a copy of the array.
Is there a workaround in Mathematica 8?
Eric Michielssen