10 #ifndef EIGEN_AUTODIFF_SCALAR_H 11 #define EIGEN_AUTODIFF_SCALAR_H 17 template<
typename A,
typename B>
19 static void run(A&, B&) {}
23 template<
typename A,
typename B>
24 void make_coherent(
const A& a,
const B&b)
59 template<
typename _DerType>
62 <_DerType, !internal::is_same<typename internal::traits<typename internal::remove_all<_DerType>::type>::Scalar,
63 typename NumTraits<typename internal::traits<typename internal::remove_all<_DerType>::type>::Scalar>::Real>::value>
73 using Base::operator+;
74 using Base::operator*;
82 : m_value(value), m_derivatives(DerType::Zero(nbDer))
84 m_derivatives.coeffRef(derNumber) =
Scalar(1);
92 if(m_derivatives.size()>0)
93 m_derivatives.setZero();
98 : m_value(value), m_derivatives(der)
101 template<
typename OtherDerType>
103 : m_value(other.value()), m_derivatives(other.derivatives())
106 friend std::ostream & operator << (std::ostream & s,
const AutoDiffScalar& a)
108 return s << a.value();
112 : m_value(other.value()), m_derivatives(other.derivatives())
115 template<
typename OtherDerType>
118 m_value = other.value();
119 m_derivatives = other.derivatives();
125 m_value = other.value();
126 m_derivatives = other.derivatives();
133 inline const Scalar& value()
const {
return m_value; }
134 inline Scalar& value() {
return m_value; }
136 inline const DerType& derivatives()
const {
return m_derivatives; }
137 inline DerType& derivatives() {
return m_derivatives; }
139 inline bool operator< (
const Scalar& other)
const {
return m_value < other; }
140 inline bool operator<=(
const Scalar& other)
const {
return m_value <= other; }
141 inline bool operator> (
const Scalar& other)
const {
return m_value > other; }
142 inline bool operator>=(
const Scalar& other)
const {
return m_value >= other; }
143 inline bool operator==(
const Scalar& other)
const {
return m_value == other; }
144 inline bool operator!=(
const Scalar& other)
const {
return m_value != other; }
146 friend inline bool operator< (
const Scalar& a,
const AutoDiffScalar& b) {
return a < b.value(); }
147 friend inline bool operator<=(
const Scalar& a,
const AutoDiffScalar& b) {
return a <= b.value(); }
148 friend inline bool operator> (
const Scalar& a,
const AutoDiffScalar& b) {
return a > b.value(); }
149 friend inline bool operator>=(
const Scalar& a,
const AutoDiffScalar& b) {
return a >= b.value(); }
150 friend inline bool operator==(
const Scalar& a,
const AutoDiffScalar& b) {
return a == b.value(); }
151 friend inline bool operator!=(
const Scalar& a,
const AutoDiffScalar& b) {
return a != b.value(); }
153 template<
typename OtherDerType>
inline bool operator< (const AutoDiffScalar<OtherDerType>& b)
const {
return m_value < b.value(); }
154 template<
typename OtherDerType>
inline bool operator<=(const AutoDiffScalar<OtherDerType>& b)
const {
return m_value <= b.value(); }
186 template<
typename OtherDerType>
190 internal::make_coherent(m_derivatives, other.derivatives());
192 m_value + other.value(),
193 m_derivatives + other.derivatives());
196 template<
typename OtherDerType>
200 (*this) = (*this) + other;
212 return AutoDiffScalar<CwiseUnaryOp<internal::scalar_opposite_op<Scalar>,
const DerType> >
213 (a - b.value(), -b.derivatives());
222 template<
typename OtherDerType>
226 internal::make_coherent(m_derivatives, other.derivatives());
228 m_value - other.value(),
229 m_derivatives - other.derivatives());
232 template<
typename OtherDerType>
236 *
this = *
this - other;
240 inline const AutoDiffScalar<CwiseUnaryOp<internal::scalar_opposite_op<Scalar>,
const DerType> >
243 return AutoDiffScalar<CwiseUnaryOp<internal::scalar_opposite_op<Scalar>,
const DerType> >(
251 return AutoDiffScalar<CwiseUnaryOp<internal::scalar_multiple_op<Scalar>,
const DerType> >(
253 (m_derivatives * other));
256 friend inline const AutoDiffScalar<CwiseUnaryOp<internal::scalar_multiple_op<Scalar>,
const DerType> >
259 return AutoDiffScalar<CwiseUnaryOp<internal::scalar_multiple_op<Scalar>,
const DerType> >(
261 a.derivatives() * other);
280 inline const AutoDiffScalar<CwiseUnaryOp<internal::scalar_multiple_op<Scalar>,
const DerType> >
283 return AutoDiffScalar<CwiseUnaryOp<internal::scalar_multiple_op<Scalar>,
const DerType> >(
285 (m_derivatives * (
Scalar(1)/other)));
288 friend inline const AutoDiffScalar<CwiseUnaryOp<internal::scalar_multiple_op<Scalar>,
const DerType> >
291 return AutoDiffScalar<CwiseUnaryOp<internal::scalar_multiple_op<Scalar>,
const DerType> >(
293 a.derivatives() * (
Scalar(-other) / (a.value()*a.value())));
312 template<
typename OtherDerType>
313 inline const AutoDiffScalar<CwiseUnaryOp<internal::scalar_multiple_op<Scalar>,
319 internal::make_coherent(m_derivatives, other.derivatives());
320 return AutoDiffScalar<CwiseUnaryOp<internal::scalar_multiple_op<Scalar>,
321 const CwiseBinaryOp<internal::scalar_difference_op<Scalar>,
322 const CwiseUnaryOp<internal::scalar_multiple_op<Scalar>,
const DerType>,
324 m_value / other.value(),
325 ((m_derivatives * other.value()) - (m_value * other.derivatives()))
326 * (
Scalar(1)/(other.value()*other.value())));
329 template<
typename OtherDerType>
331 const CwiseUnaryOp<internal::scalar_multiple_op<Scalar>,
const DerType>,
335 internal::make_coherent(m_derivatives, other.derivatives());
337 const CwiseUnaryOp<internal::scalar_multiple_op<Scalar>,
const DerType>,
339 m_value * other.value(),
340 (m_derivatives * other.value()) + (m_value * other.derivatives()));
345 *
this = *
this * other;
349 template<
typename OtherDerType>
352 *
this = *
this * other;
358 *
this = *
this / other;
362 template<
typename OtherDerType>
365 *
this = *
this / other;
371 DerType m_derivatives;
377 template<
typename _DerType>
412 derived().value() += other;
421 derived().value() * other,
422 derived().derivatives() * other);
428 return AutoDiffScalar<typename CwiseUnaryOp<scalar_multiple2_op<Scalar,Real>, DerType>::Type >(
430 a.derivatives() * other);
435 *
this = *
this * other;
440 template<
typename _DerType>
448 template<
typename A_Scalar,
int A_Rows,
int A_Cols,
int A_Options,
int A_MaxRows,
int A_MaxCols,
typename B>
451 static void run(A& a, B& b) {
460 template<
typename A,
typename B_Scalar,
int B_Rows,
int B_Cols,
int B_Options,
int B_MaxRows,
int B_MaxCols>
463 static void run(A& a, B& b) {
472 template<
typename A_Scalar,
int A_Rows,
int A_Cols,
int A_Options,
int A_MaxRows,
int A_MaxCols,
473 typename B_Scalar,
int B_Rows,
int B_Cols,
int B_Options,
int B_MaxRows,
int B_MaxCols>
475 Matrix<B_Scalar, B_Rows, B_Cols, B_Options, B_MaxRows, B_MaxCols> > {
478 static void run(A& a, B& b) {
492 template<
typename A_Scalar,
int A_Rows,
int A_Cols,
int A_Options,
int A_MaxRows,
int A_MaxCols>
495 enum { Defined = 1 };
499 template<
typename A_Scalar,
int A_Rows,
int A_Cols,
int A_Options,
int A_MaxRows,
int A_MaxCols>
502 enum { Defined = 1 };
506 template<
typename DerType>
509 enum { Defined = 1 };
513 template<
typename DerType>
516 enum { Defined = 1 };
522 #define EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(FUNC,CODE) \ 523 template<typename DerType> \ 524 inline const Eigen::AutoDiffScalar<Eigen::CwiseUnaryOp<Eigen::internal::scalar_multiple_op<typename Eigen::internal::traits<typename Eigen::internal::remove_all<DerType>::type>::Scalar>, const typename Eigen::internal::remove_all<DerType>::type> > \ 525 FUNC(const Eigen::AutoDiffScalar<DerType>& x) { \ 526 using namespace Eigen; \ 527 typedef typename Eigen::internal::traits<typename Eigen::internal::remove_all<DerType>::type>::Scalar Scalar; \ 528 typedef AutoDiffScalar<CwiseUnaryOp<Eigen::internal::scalar_multiple_op<Scalar>, const typename Eigen::internal::remove_all<DerType>::type> > ReturnType; \ 532 template<
typename DerType>
534 template<
typename DerType>
536 template<
typename DerType>
538 template<
typename DerType,
typename T>
540 template<
typename DerType,
typename T>
542 template<
typename DerType,
typename T>
544 template<
typename DerType,
typename T>
547 EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(abs,
551 EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(abs2,
553 return ReturnType(abs2(x.
value()), x.derivatives() * (
Scalar(2)*x.
value()));)
555 EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(sqrt,
557 Scalar sqrtx = sqrt(x.
value());
558 return ReturnType(sqrtx,x.derivatives() * (
Scalar(0.5) / sqrtx));)
560 EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(cos,
563 return ReturnType(cos(x.
value()), x.derivatives() * (-sin(x.
value())));)
565 EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(sin,
568 return ReturnType(sin(x.
value()),x.derivatives() * cos(x.
value()));)
570 EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(exp,
572 Scalar expx = exp(x.
value());
573 return ReturnType(expx,x.derivatives() * expx);)
575 EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(log,
579 template<typename DerType>
583 using namespace Eigen;
586 std::pow(x.value(),y),
587 x.derivatives() * (y * std::pow(x.value(),y-1)));
591 template<
typename DerTypeA,
typename DerTypeB>
600 ret.value() = atan2(a.value(), b.value());
602 Scalar tmp2 = a.value() * a.value();
603 Scalar tmp3 = b.value() * b.value();
604 Scalar tmp4 = tmp3/(tmp2+tmp3);
607 ret.derivatives() = (a.derivatives() * b.value() - a.value() * b.derivatives()) * (tmp2+tmp3);
612 EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(tan,
615 return ReturnType(tan(x.value()),x.derivatives() * (
Scalar(1)/numext::abs2(cos(x.value()))));)
617 EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(asin,
620 return ReturnType(asin(x.value()),x.derivatives() * (
Scalar(1)/sqrt(1-numext::abs2(x.value()))));)
622 EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(acos,
625 return ReturnType(acos(x.value()),x.derivatives() * (
Scalar(-1)/sqrt(1-numext::abs2(x.value()))));)
627 #undef EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY
636 RequireInitialization = 1
642 #endif // EIGEN_AUTODIFF_SCALAR_H AutoDiffScalar(const Scalar &value, int nbDer, int derNumber)
Constructs an active scalar from its value, and initializes the nbDer derivatives such that it corres...
Definition: AutoDiffScalar.h:81
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_inverse_mult_op< typename Derived::Scalar >, const Derived > operator/(const typename Derived::Scalar &s, const Eigen::ArrayBase< Derived > &a)
Component-wise division of a scalar by array elements.
Definition: GlobalFunctions.h:74
const Scalar & value() const
Definition: SparseUtil.h:164
A scalar type replacement with automatic differentation capability.
Definition: AutoDiffScalar.h:60
AutoDiffScalar()
Default constructor without any initialization.
Definition: AutoDiffScalar.h:77
iterative scaling algorithm to equilibrate rows and column norms in matrices
Definition: TestIMU_Common.h:87
Holds information about the various numeric (i.e.
Definition: NumTraits.h:88
const internal::permut_matrix_product_retval< PermutationDerived, Derived, OnTheRight > operator*(const MatrixBase< Derived > &matrix, const PermutationBase< PermutationDerived > &permutation)
Definition: PermutationMatrix.h:539
Definition: AutoDiffScalar.h:18
OSVR_TimeValue operator+(OSVR_TimeValue const &tv, std::chrono::duration< Rep, Period > const &additionalTime)
Add a util::time::TimeValue and a std::chrono::duration.
Definition: TimeValueChrono.h:45
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition: CwiseBinaryOp.h:107
Definition: AutoDiffScalar.h:29
EIGEN_STRONG_INLINE void resize(Index nbRows, Index nbCols)
Resizes *this to a rows x cols matrix.
Definition: PlainObjectBase.h:235
AutoDiffScalar(const Real &value)
Conversion from a scalar constant to an active scalar.
Definition: AutoDiffScalar.h:89
time_value_scalar_duration operator-(detail::TimeValueChronoWrapperBase< DerivedA > const &a, detail::TimeValueChronoWrapperBase< DerivedB > const &b)
Subtract one wrapped TimeValue from another and get a std::duration back!
Definition: TimeValueChrono.h:202
Derived & setZero(Index size)
Resizes to the given size, and sets all coefficients in this expression to zero.
Definition: CwiseNullaryOp.h:515
Definition: BandTriangularSolver.h:13
Definition: Functors.h:504
const int Dynamic
This value means that a positive quantity (e.g., a size) is not known at compile-time, and that instead the value is stored in some runtime variable.
Definition: Constants.h:21
AutoDiffScalar(const Scalar &value, const DerType &der)
Constructs an active scalar from its value and derivatives der.
Definition: AutoDiffScalar.h:97
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:59
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:127
Definition: ForwardDeclarations.h:17
double Scalar
Common scalar type.
Definition: FlexibleKalmanBase.h:48