0.6: how do you broadcast `call` over a vector of functions?

As an illustration:

julia> f=(x->x,x->x^2)
(#5,#6)

julia> apply(fs::Tuple, x) = _apply(x, (), fs...)
apply (generic function with 1 method)

julia> _apply(x, out::Tuple) = out
_apply (generic function with 1 method)

julia> @inline _apply(x, out::Tuple, f, fs...) = _apply(x, (out..., f(x)), fs...)
_apply (generic function with 2 methods)

julia> @time apply(f, 0.1)
  0.005076 seconds (2.81 k allocations: 133.484 KB)
(0.1,0.010000000000000002)

julia> @time apply(f, 0.1)
  0.000002 seconds (5 allocations: 192 bytes)
(0.1,0.010000000000000002)

julia> @time apply(f, 0.2)
  0.000002 seconds (5 allocations: 192 bytes)
(0.2,0.04000000000000001)

That’s a 10^4 speed improvement.

2 Likes