What is interaction between F.() broadcasting and keyword args?



How does F.(a, b; c=d) work with respect to broadcasting? I understand that the arguments a, b will be broadcast. What about the keyword argument?


F.(a, b; c=d) is equivalent to broadcast((a,b) -> F(a, b; c=d), a, b). That is, it does not broadcast over the keyword arguments, but instead passes them inside the closure.


Any workaround to broadcast the keyword arguments? Should I lower these to a _func?


Just call broadcast explicitly and you can use whatever arguments you want.


This is suppose to be a friendly end-user APIā€¦ I ended up lowering the function and checking whether any of the arguments where AbstractVector to decide on whether to broadcast or not. Poor man type dispatch since there are too many combinations for a simple type dispatch.


I came across this thread after encountering a similar situation. The code below seems to offer a feasible solution. Note that there might be a small performance penalty for very simple functions, such as the example below, but it seems to be negligible in most cases.

f(a,b) = a + b
f(;a,b) = f.(a,b)


julia> f(;a=1,b=2)

julia> f(;a=1,b=[1,2])
2-element Array{Int64,1}: