ApproxFun.jl icon indicating copy to clipboard operation
ApproxFun.jl copied to clipboard

Compatibility with ForwardDiff.Dual

Open hstrey opened this issue 2 years ago • 6 comments

I would like to use Approxfun for creating custom distributions in Turing.jl but it seems that Approxfun is not compatible with ForwardDiff.Dual

using ForwardDiff, ApproxFun
f = Fun(x->exp(ForwardDiff.Dual(x,1)))

throws: ERROR: LoadError: type ForwardDiff.Dual{Nothing, Float64, 1} not supported

Since Approxfun.jl is compatible with DualNumbers.jl, I assumed that it would be compatible with ForwardDiff.Dual. Any thoughts?

hstrey avatar Jan 21 '22 18:01 hstrey

https://github.com/JuliaApproximation/ApproxFun.jl/blob/master/src/Extras/dualnumbers.jl

dlfivefifty avatar Jan 21 '22 19:01 dlfivefifty

are you saying that it is working, or that you are in the process of implementing it? I am happy to help if it is in my set of skills.

hstrey avatar Jan 21 '22 19:01 hstrey

That’s a link to what I needed to add DualNumbers.jl support. Probably you can copy it for ForwardDiff.jl

dlfivefifty avatar Jan 21 '22 20:01 dlfivefifty

thanks. I will give it a try. Can't we just fake compatibility by returning the derivatives from the FUNs. f(x::Dual) = Dual(f(x.value),f(x.partials)*f'(x.value)) - I am paraphrasing

hstrey avatar Jan 21 '22 20:01 hstrey

Seems different than what you first asked

dlfivefifty avatar Jan 21 '22 21:01 dlfivefifty

this package uses DualNumbers.Dual. ForwardDiff uses ForwardDiff.Dual

longemen3000 avatar May 07 '22 02:05 longemen3000