Compile and arrays
- To: mathgroup at smc.vnet.net
- Subject: [mg114187] Compile and arrays
- From: "Eric Michielssen" <emichiel at eecs.umich.edu>
- Date: Fri, 26 Nov 2010 05:30:06 -0500 (EST)
Compiled functions that act on subarrays of supplied arrays often run very
slow.
As an example, consider the following two routines "Ctest" (compiled) and
"test" (standard mathematica). They do the same, namely extract the first
row from matrices a and b, and add them.
Ctest = Compile[{{a,_Real,2},{b,_Real,2}}, Module[{c},c = a[[1]] +
b[[1]];Return[c]]];
test[a_,b_]:=Module[{c},c = a[[1]] + b[[1]];Return[c]];
Oftentimes, Ctest is two orders of magnitude slower than test, implying that
the routine lacks information on the size of the two matrices to loop fast.
Is there a remedy/workaround for this in Mathematica 8?
Thanks,
Eric Michielssen