I’m trying to figure out the “right” way to combine broadcasting with functions for vector-valued inputs/outputs. For example, the following function defines foo
through broadcasted operations.
using LinearAlgebra
function foo(a,b)
return a.*b, a.+b
end
c,d = foo(collect(1:3),collect(0:2))
- Is there a way to perform the same operation using the non-broadcast version of
foo
? Usingfoo.(a,b)
with the scalar version offoo
returns an array of tuples, instead of the tuple of arrays in the broadcast version. - Is it OK to just define all functions using broadcast operations (so that they work for both scalar and vectorized inputs), or will there be some performance hit?
Thanks!