AutoDiffJacobian.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 //
00006 // This Source Code Form is subject to the terms of the Mozilla
00007 // Public License v. 2.0. If a copy of the MPL was not distributed
00008 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
00009 
00010 #ifndef EIGEN_AUTODIFF_JACOBIAN_H
00011 #define EIGEN_AUTODIFF_JACOBIAN_H
00012 
00013 namespace Eigen
00014 {
00015 
00016 template<typename Functor> class AutoDiffJacobian : public Functor
00017 {
00018 public:
00019   AutoDiffJacobian() : Functor() {}
00020   AutoDiffJacobian(const Functor& f) : Functor(f) {}
00021 
00022   // forward constructors
00023   template<typename T0>
00024   AutoDiffJacobian(const T0& a0) : Functor(a0) {}
00025   template<typename T0, typename T1>
00026   AutoDiffJacobian(const T0& a0, const T1& a1) : Functor(a0, a1) {}
00027   template<typename T0, typename T1, typename T2>
00028   AutoDiffJacobian(const T0& a0, const T1& a1, const T2& a2) : Functor(a0, a1, a2) {}
00029 
00030   enum {
00031     InputsAtCompileTime = Functor::InputsAtCompileTime,
00032     ValuesAtCompileTime = Functor::ValuesAtCompileTime
00033   };
00034 
00035   typedef typename Functor::InputType InputType;
00036   typedef typename Functor::ValueType ValueType;
00037   typedef typename Functor::JacobianType JacobianType;
00038   typedef typename JacobianType::Scalar Scalar;
00039   typedef typename JacobianType::Index Index;
00040 
00041   typedef Matrix<Scalar,InputsAtCompileTime,1> DerivativeType;
00042   typedef AutoDiffScalar<DerivativeType> ActiveScalar;
00043 
00044 
00045   typedef Matrix<ActiveScalar, InputsAtCompileTime, 1> ActiveInput;
00046   typedef Matrix<ActiveScalar, ValuesAtCompileTime, 1> ActiveValue;
00047 
00048   void operator() (const InputType& x, ValueType* v, JacobianType* _jac=0) const
00049   {
00050     eigen_assert(v!=0);
00051     if (!_jac)
00052     {
00053       Functor::operator()(x, v);
00054       return;
00055     }
00056 
00057     JacobianType& jac = *_jac;
00058 
00059     ActiveInput ax = x.template cast<ActiveScalar>();
00060     ActiveValue av(jac.rows());
00061 
00062     if(InputsAtCompileTime==Dynamic)
00063       for (Index j=0; j<jac.rows(); j++)
00064         av[j].derivatives().resize(this->inputs());
00065 
00066     for (Index i=0; i<jac.cols(); i++)
00067       ax[i].derivatives() = DerivativeType::Unit(this->inputs(),i);
00068 
00069     Functor::operator()(ax, &av);
00070 
00071     for (Index i=0; i<jac.rows(); i++)
00072     {
00073       (*v)[i] = av[i].value();
00074       jac.row(i) = av[i].derivatives();
00075     }
00076   }
00077 protected:
00078 
00079 };
00080 
00081 }
00082 
00083 #endif // EIGEN_AUTODIFF_JACOBIAN_H


win_eigen
Author(s): Daniel Stonier
autogenerated on Mon Oct 6 2014 12:24:08