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_ADLOC_FORWARD
00026 #define EIGEN_ADLOC_FORWARD
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #define ADOLC_TAPELESS
00040 #ifndef NUMBER_DIRECTIONS
00041 # define NUMBER_DIRECTIONS 2
00042 #endif
00043 #include <adolc/adouble.h>
00044
00045
00046 #if defined(malloc)
00047 # undef malloc
00048 #endif
00049
00050 #if defined(calloc)
00051 # undef calloc
00052 #endif
00053
00054 #if defined(realloc)
00055 # undef realloc
00056 #endif
00057
00058 #include <Eigen/Core>
00059
00060 namespace Eigen {
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 }
00083
00084
00085
00086
00087 namespace Eigen {
00088
00089 namespace internal {
00090
00091 inline const adtl::adouble& conj(const adtl::adouble& x) { return x; }
00092 inline const adtl::adouble& real(const adtl::adouble& x) { return x; }
00093 inline adtl::adouble imag(const adtl::adouble&) { return 0.; }
00094 inline adtl::adouble abs(const adtl::adouble& x) { return adtl::fabs(x); }
00095 inline adtl::adouble abs2(const adtl::adouble& x) { return x*x; }
00096
00097 using adtl::sqrt;
00098 using adtl::exp;
00099 using adtl::log;
00100 using adtl::sin;
00101 using adtl::cos;
00102 using adtl::pow;
00103
00104 }
00105
00106 }
00107
00108 namespace Eigen {
00109
00110 template<> struct NumTraits<adtl::adouble>
00111 {
00112 typedef adtl::adouble Real;
00113 typedef adtl::adouble NonInteger;
00114 typedef adtl::adouble Nested;
00115 enum {
00116 IsComplex = 0,
00117 IsInteger = 0,
00118 IsSigned = 1,
00119 RequireInitialization = 1,
00120 ReadCost = 1,
00121 AddCost = 1,
00122 MulCost = 1
00123 };
00124 };
00125
00126 template<typename Functor> class AdolcForwardJacobian : public Functor
00127 {
00128 typedef adtl::adouble ActiveScalar;
00129 public:
00130
00131 AdolcForwardJacobian() : Functor() {}
00132 AdolcForwardJacobian(const Functor& f) : Functor(f) {}
00133
00134
00135 template<typename T0>
00136 AdolcForwardJacobian(const T0& a0) : Functor(a0) {}
00137 template<typename T0, typename T1>
00138 AdolcForwardJacobian(const T0& a0, const T1& a1) : Functor(a0, a1) {}
00139 template<typename T0, typename T1, typename T2>
00140 AdolcForwardJacobian(const T0& a0, const T1& a1, const T1& a2) : Functor(a0, a1, a2) {}
00141
00142 typedef typename Functor::InputType InputType;
00143 typedef typename Functor::ValueType ValueType;
00144 typedef typename Functor::JacobianType JacobianType;
00145
00146 typedef Matrix<ActiveScalar, InputType::SizeAtCompileTime, 1> ActiveInput;
00147 typedef Matrix<ActiveScalar, ValueType::SizeAtCompileTime, 1> ActiveValue;
00148
00149 void operator() (const InputType& x, ValueType* v, JacobianType* _jac) const
00150 {
00151 eigen_assert(v!=0);
00152 if (!_jac)
00153 {
00154 Functor::operator()(x, v);
00155 return;
00156 }
00157
00158 JacobianType& jac = *_jac;
00159
00160 ActiveInput ax = x.template cast<ActiveScalar>();
00161 ActiveValue av(jac.rows());
00162
00163 for (int j=0; j<jac.cols(); j++)
00164 for (int i=0; i<jac.cols(); i++)
00165 ax[i].setADValue(j, i==j ? 1 : 0);
00166
00167 Functor::operator()(ax, &av);
00168
00169 for (int i=0; i<jac.rows(); i++)
00170 {
00171 (*v)[i] = av[i].getValue();
00172 for (int j=0; j<jac.cols(); j++)
00173 jac.coeffRef(i,j) = av[i].getADValue(j);
00174 }
00175 }
00176 protected:
00177
00178 };
00179
00180
00181
00182 }
00183
00184 #endif // EIGEN_ADLOC_FORWARD