Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
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