Help with ForwardDiff2

I cant’s seem to make this kind of code work with ForwardDiff2


function gaussian(f,N)
    a=-8.38149 # exp(-x^2/2)/sqrt(2π) == eps(1.0)
    b=8.38149
    dx=(b-a)/(N)
    Δ=(b-a)/(2N)
    x=a+Δ
    I=(exp(-x*x/2).*f(x)).*dx
    for i in 2:N
        x=a+Δ*(2i-1)
        I=I.+(exp(-x*x/2).*f(x)).*dx
    end
    I/sqrt(2*π)
end

using ForwardDiff2: DI


f(α) = gaussian(x->tanh(x+α),100)

f(2.0) # 0.8646647167633871

DI(f)(2.0)

using StaticArrays

g(α) = gaussian(x->@SVector([tanh(2x+α),tanh(x+α)]),100)

g(2.0) #  [0.6389517914690043, 0.8646647167633871]

DI(g)(2.0)

the error message it gives is about type promotion from Float64 to Dual

is there a known workaround?

thank you guys!

EDIT.

altough immensely inelegant, i managed to get excellent performance via manually using ForwardDiff Dual type.

Hi @francesco.alemanno, could you post an example on how you solved the problem? Thank you