I've got a piece of code that involves passing a user-specified function fairly far down the call stack, to be called in a tight loop. It's an integration/quadrature routine FWIW. I'm seeing that the type of the function is not specialized on, i.e. Julia is interpreting in the most important hot loop in this code. Is there a way to ensure that f
will have its type inferred? Or is it maybe not even worth it due to code duplication / monomorphization costs? I realized I'm not sure if monomorphization is a thing in Julia or not, although I imagine it is.
One way to specialize on a specific function type is:
function generic(f::F, a, b) where {F <: Function}
f(a,b)
end
Last updated: Nov 22 2024 at 04:41 UTC