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

Replace values of Duals with other numbers

Open jwscook opened this issue 4 years ago • 1 comments

See my gist for what I'm trying to achieve.

I'm using NLsolve to find the cartesian coordinates given curvilinear coordinates and a function that returns curvilinear coordinates given cartesian coordinates (the reciprocal function is not usually easy / possible to write down). I want to be able to perform multiple AD passes through the solver function as though I had written down the complicated forward transform. I hope that makes sense - the gist should help.

I can't think of a good way of manipulating the values inside a Dual to acheive the desired outcome. Is there a good way?

jwscook avatar Jun 25 '21 16:06 jwscook

The most straightforward answer is that you can't, they are immutable. And your gist doesn't try, despite its name changevalue!(x::Dual, ... returns an altered dual, without changing its argument. And changevalue!(x::AbstractVector ... writes what it returns into the (mutable) array x. Which sounds fine.

mcabbott avatar Jul 17 '21 23:07 mcabbott