From 40774c625e7d47898bb171287c508c99b0b14fc0 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 27 Feb 2009 16:19:13 +0000 Subject: add a proof of concept autodiff jacobian helper class based on adolc with unit test and FindAdolc cmake module --- unsupported/Eigen/AdolcForward | 60 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) (limited to 'unsupported/Eigen/AdolcForward') diff --git a/unsupported/Eigen/AdolcForward b/unsupported/Eigen/AdolcForward index 2d65988d6..531b2ae5f 100644 --- a/unsupported/Eigen/AdolcForward +++ b/unsupported/Eigen/AdolcForward @@ -98,9 +98,9 @@ namespace adtl { } -namespace Eigen { namespace unsupported { /*@}*/ } } +namespace Eigen { -template<> struct EigenNumTraits +template<> struct NumTraits { typedef adtl::adouble Real; typedef adtl::adouble FloatingPoint; @@ -113,4 +113,60 @@ template<> struct EigenNumTraits }; }; +template class AdolcForwardJacobian : public Functor +{ + typedef adtl::adouble ActiveScalar; +public: + + AdolcForwardJacobian() : Functor() {} + AdolcForwardJacobian(const Functor& f) : Functor(f) {} + + // forward constructors + template + AdolcForwardJacobian(const T0& a0) : Functor(a0) {} + template + AdolcForwardJacobian(const T0& a0, const T1& a1) : Functor(a0, a1) {} + template + AdolcForwardJacobian(const T0& a0, const T1& a1, const T1& a2) : Functor(a0, a1, a2) {} + + typedef typename Functor::InputType InputType; + typedef typename Functor::ValueType ValueType; + typedef typename Functor::JacobianType JacobianType; + + typedef Matrix ActiveInput; + typedef Matrix ActiveValue; + + void operator() (const InputType& x, ValueType* v, JacobianType* _jac) const + { + ei_assert(v!=0); + if (!_jac) + { + Functor::operator()(x, v); + return; + } + + JacobianType& jac = *_jac; + + ActiveInput ax = x.template cast(); + ActiveValue av(jac.rows()); + + for (int j=0; j