Martin:
Please bear with me. I am also learning about compiled functions. And you taught me how to pass in lists and matrices to a compiled function. THANKS
I managed to get this to work:
cIterReal = Compile[
{
{vecPosAct, _Real, 2},
{boxWidth, _Real},
{boxWidth2, _Real},
{c, _Integer}
}
,
Module[
{
vecPosActNew,
check
}
,
vecPosActNew = vecPosAct;
Do[
vecPosActNew[[check]] -=
Round[(vecPosAct[[check]] - boxWidth2)/boxWidth]*boxWidth2*1.
,
{check, 1, c, 1}
];
vecPosActNew
],
CompilationTarget -> "C"
, CompilationOptions -> {"InlineExternalDefinitions" -> True}
];
Now,
cIterReal[{{3.2, 4., 9.}, {2.3, 4., 9.}, {9.2, 3.2, 5.0}}, 2.2, 1.1, 3]
Returns:
{{2.1, 2.9, 4.6}, {1.2, 2.9, 4.6}, {4.8, 2.1, 2.8}}
Remember that Do does not return anything. The docs say:
Unless an explicit Return is used, the value returned by Do is Null.
I hope that helps. I'd be interested to hear how much of a performance boost this gives you.
Have a great rest of your week.