On Tue, 15 Nov 2016, Sven Schreiber wrote:
Hi,
say 'ms' is an array of matrices, then it isn't currently possible to pass an
element to a function like this, in pointer form: "fcall(&ms[1])"
It is of course easy to work around this by making a temporary copy. However,
if one wants to use the pointer form for performance reasons to avoid that
copy, then it's a pity that arrays cannot be used. Are there any plans to
allow this, or perhaps recommendations what to do instead?
A recommendation, anyway: if you're doing the pointer thing just for
performance reasons, use a "const matrix" parameter instead. Then (as
with pointer form) the function argument won't get copied, just shared
with the function.
<hansl>
function scalar getmat (matrix m)
return 0
end function
function scalar getconstmat (const matrix m)
return 0
end function
matrices M = array(2)
M[1] = mnormal(1000,1000)
M[2] = ones(2,2)
set stopwatch
loop 1000 -q
getmat(M[1])
endloop
printf "regular matrix arg: %.4f\n", $stopwatch
loop 1000 -q
getconstmat(M[1])
endloop
printf "const matrix arg: %.4f\n", $stopwatch
</hansl>
Here I see:
regular matrix arg: 1.0640
const matrix arg: 0.0068
Allin