Input Type

Hi, in a solver framework I am using a custom function which takes Array{<:**AbstractFloat,**1} as input.
In practice, This AbstractFloat can be either Float32 or Float64. In terms of performances, should I create two functions, dealing respectively with Float32 and Float64? Btw this also means to maintain two functions doing the same thing. Or the evaluation cost using AbstractFloat is fine?

A method is always compiled anew for each new set of concrete types it receives. Your type signature does not reflect the types of the input arguments themselves, but it’s like a funnel which accepts certain concrete types for your method. As long as you only feed it Vector{Float64} or Vector{Float32} you will not have any costs related to AbstractFloat

Regarding Float32 and Float64, this should work fine as long as you don’t use Float64 literals in your code that convert Float32 input to Float64 when multiplied or otherwise combined.

1 Like

Ty for your help, I understand better now!