I have an array of functions that each return a float, and so I am trying to assign the results of those functions to an array. So I had something like this
results = similar(f_arr, Float64)
results .= [f(a, b, c) for f in f_arr]
however this is 10+ times slower than manually calling each function in the array, as in
results = similar(f_arr, Float64)
results[1] = f1(a, b, c)
results[2] = f2(a, b, c)
...
Is there an explanation as to why the first way is so slow? I also tried something like the following
results = similar(f_arr, Float64)
results .= [f_arr[i](a, b, c) for i in 1:length(f_arr)]
and I got an error because the tuple (a, b, c)
was getting passed to f_arr[i]
instead of passing all three variables in the first two code blocks. I am fairly new to Julia so maybe there is some piece of documentation I am missing, and I would love to be pointed in the right direction.