Quantcast
Channel: First steps - JuliaLang
Viewing all articles
Browse latest Browse all 2795

"Right" way to broadcast vector-valued functions?

$
0
0

@jlchan wrote:

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? Using foo.(a,b) with the scalar version of foo 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!

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 2795

Latest Images

Trending Articles



Latest Images