Stream: helpdesk (published)

Topic: Specialization of `Function` arguments to recursive algor...


view this post on Zulip Jack C (Apr 05 2022 at 15:01):

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.

view this post on Zulip mbaz (Apr 05 2022 at 15:22):

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: Oct 02 2023 at 04:34 UTC