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 // Eigen is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 3 of the License, or (at your option) any later version.
00010 //
00011 // Alternatively, you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License as
00013 // published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License and a copy of the GNU General Public License along with
00023 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00024 
00025 #ifndef EIGEN_AUTODIFF_JACOBIAN_H
00026 #define EIGEN_AUTODIFF_JACOBIAN_H
00027 
00028 namespace Eigen
00029 {
00030 
00031 template<typename Functor> class AutoDiffJacobian : public Functor
00032 {
00033 public:
00034   AutoDiffJacobian() : Functor() {}
00035   AutoDiffJacobian(const Functor& f) : Functor(f) {}
00036 
00037   // forward constructors
00038   template<typename T0>
00039   AutoDiffJacobian(const T0& a0) : Functor(a0) {}
00040   template<typename T0, typename T1>
00041   AutoDiffJacobian(const T0& a0, const T1& a1) : Functor(a0, a1) {}
00042   template<typename T0, typename T1, typename T2>
00043   AutoDiffJacobian(const T0& a0, const T1& a1, const T1& a2) : Functor(a0, a1, a2) {}
00044 
00045   enum {
00046     InputsAtCompileTime = Functor::InputsAtCompileTime,
00047     ValuesAtCompileTime = Functor::ValuesAtCompileTime
00048   };
00049 
00050   typedef typename Functor::InputType InputType;
00051   typedef typename Functor::ValueType ValueType;
00052   typedef typename Functor::JacobianType JacobianType;
00053   typedef typename JacobianType::Scalar Scalar;
00054   typedef typename JacobianType::Index Index;
00055 
00056   typedef Matrix<Scalar,InputsAtCompileTime,1> DerivativeType;
00057   typedef AutoDiffScalar<DerivativeType> ActiveScalar;
00058 
00059 
00060   typedef Matrix<ActiveScalar, InputsAtCompileTime, 1> ActiveInput;
00061   typedef Matrix<ActiveScalar, ValuesAtCompileTime, 1> ActiveValue;
00062 
00063   void operator() (const InputType& x, ValueType* v, JacobianType* _jac=0) const
00064   {
00065     eigen_assert(v!=0);
00066     if (!_jac)
00067     {
00068       Functor::operator()(x, v);
00069       return;
00070     }
00071 
00072     JacobianType& jac = *_jac;
00073 
00074     ActiveInput ax = x.template cast<ActiveScalar>();
00075     ActiveValue av(jac.rows());
00076 
00077     if(InputsAtCompileTime==Dynamic)
00078       for (Index j=0; j<jac.rows(); j++)
00079         av[j].derivatives().resize(this->inputs());
00080 
00081     for (Index i=0; i<jac.cols(); i++)
00082       ax[i].derivatives() = DerivativeType::Unit(this->inputs(),i);
00083 
00084     Functor::operator()(ax, &av);
00085 
00086     for (Index i=0; i<jac.rows(); i++)
00087     {
00088       (*v)[i] = av[i].value();
00089       jac.row(i) = av[i].derivatives();
00090     }
00091   }
00092 protected:
00093 
00094 };
00095 
00096 }
00097 
00098 #endif // EIGEN_AUTODIFF_JACOBIAN_H


libicr
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:32:29