What is the best practice to store in place the results of a function returning multiple arrays?
A simple non-MWE:
f(x,y,z) = 1 ./ x, y'.*y, 2*z # the actual function is long and complex, with matrix operations
n = 10
x = y = z = rand(n)
fx, fy, fz = Vector{Float64}(undef,n), Matrix{Float64}(undef,n, n), Vector{Float64}(undef,n)
fx, fy, fz .= f(x,y,z) # ERROR: MethodError: no method matching copyto!
Should we define some f!!!()
function that mutates in place the first three arguments? Example:
f!!!(fx,fy,fz,x,y,z) = @. begin fx = 1/x; fy = y'*y; fz = 2*z; return fx, fy, fz; end
f!!!(fx,fy,fz,x,y,z)
Thanks.
NB: edited original example because it had several typos.