I have the following issue:
import ForwardDiff, DiffRules, IrrationalConstants, SpecialFunctions
∂logerfcx(x) = 2 * (x - inv(SpecialFunctions.erfcx(x)) / IrrationalConstants.sqrtπ)
DiffRules.@define_diffrule SpecialFunctions.logerfcx(x) = :(∂logerfcx($x))
ForwardDiff.derivative(SpecialFunctions.logerfcx, 4)
This gives the following error:
ERROR: MethodError: no method matching _logerfcx(::ForwardDiff.Dual{ForwardDiff.Tag{typeof(SpecialFunctions.logerfcx), Int64}, Float64, 1})
Closest candidates are:
_logerfcx(::Union{Float32, Float64, BigFloat}) at ~/.julia/packages/SpecialFunctions/NBIqR/src/erf.jl:552
Stacktrace:
[1] logerfcx(x::ForwardDiff.Dual{ForwardDiff.Tag{typeof(SpecialFunctions.logerfcx), Int64}, Int64, 1})
@ SpecialFunctions ~/.julia/packages/SpecialFunctions/NBIqR/src/erf.jl:550
[2] derivative(f::typeof(SpecialFunctions.logerfcx), x::Int64)
@ ForwardDiff ~/.julia/packages/ForwardDiff/tZ5o1/src/derivative.jl:14
[3] top-level scope
@ REPL[15]:1
Why is ForwardDiff not picking up the custom rule I defined?
Related: Broadcast gradient error · Issue #1132 · FluxML/Zygote.jl · GitHub