How do I use both Julia's dot notation to do elementwise operations AND ensure that the result is saved in an already existing array?
function myfun(x, y)
return x + y
end
a = myfun(1, 2) # Results in a == 3
a = myfun.([1 2], [3; 4]) # Results in a == [4 5; 5 6]
function myfun!(x, y, out)
out .= x + y
end
a = zeros(2, 2)
myfun!.([1 2], [3; 4], a) # Results in a DimensionMismatch error
Also, does @. a = myfun([1 2], [3; 4])
write the result to a
in the same way as I am trying to achieve with myfun!()
? That is, does that line write the result directly to a
without saving storing the result anywhere else first?