|Re: [eigen] Subject: why are AutoDiff to value conversions disabled?|
[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]
If you have an autodiff type in your program they need to propagate through your program correctly.
Some pitfalls in doing so are conversions to integers and back or not "autodiff enabled" mathematical function e.g. if your implementation lacks an overloaded version of atan2(). If you don't have these conversion operators, this will result in a compile error directly pointing you to the issue.
If you enable these operators, C++ will implicity convert the autodiff type into its underlying value type at some points. Then your program will compile just fine but your derivatives will be wrong.
AFAIK there is now way to enable these operators just for use with static_cast<> and not enable them for implicit conversions.
The fix is rather easy, though: you just implement a function
template <class Scalar, class Scalar_Or_Autodiff>
Scalar value_cast(const Scalar_Or_Autodiff&);
and specialize it accordingly to just give back the Scalar or unwrap if needed.
Then you can just do value_cast<Scalar>(maybe_
Am 19.01.2017 um 08:17 schrieb Geoffrey Lalonde:
|Mail converted by MHonArc 2.6.19+||http://listengine.tuxfamily.org/|