10 #ifndef EIGEN_AUTODIFF_SCALAR_H 11 #define EIGEN_AUTODIFF_SCALAR_H 17 template<
typename A,
typename B>
23 template<
typename A,
typename 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())
108 return s << a.
value();
112 : m_value(other.value()), m_derivatives(other.derivatives())
115 template<
typename OtherDerType>
118 m_value = other.
value();
125 m_value = other.
value();
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; }
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; }
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>
192 m_value + other.
value(),
196 template<
typename OtherDerType>
200 (*this) = (*this) + other;
212 return AutoDiffScalar<CwiseUnaryOp<internal::scalar_opposite_op<Scalar>,
const DerType> >
222 template<
typename OtherDerType>
228 m_value - other.
value(),
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> >(
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> >(
312 template<
typename OtherDerType>
313 inline const AutoDiffScalar<CwiseUnaryOp<internal::scalar_multiple_op<Scalar>,
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(),
329 template<
typename OtherDerType>
331 const CwiseUnaryOp<internal::scalar_multiple_op<Scalar>,
const DerType>,
337 const CwiseUnaryOp<internal::scalar_multiple_op<Scalar>,
const DerType>,
339 m_value * other.
value(),
345 *
this = *
this * other;
349 template<
typename OtherDerType>
352 *
this = *
this * other;
358 *
this = *
this / other;
362 template<
typename OtherDerType>
365 *
this = *
this / other;
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 >(
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>
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>
549 return ReturnType(
abs(x.value()), x.derivatives() * (x.value()<0 ? -1 : 1) );)
553 return ReturnType(
abs2(x.value()), x.derivatives() * (Scalar(2)*x.value()));)
557 Scalar sqrtx =
sqrt(x.value());
558 return ReturnType(sqrtx,x.derivatives() * (Scalar(0.5) / sqrtx));)
577 return ReturnType(
log(x.value()),x.derivatives() * (Scalar(1)/x.value()));)
579 template<typename DerType>
583 using namespace Eigen;
591 template<
typename DerTypeA,
typename DerTypeB>
604 Scalar tmp4 = tmp3/(tmp2+tmp3);
636 RequireInitialization = 1
642 #endif // EIGEN_AUTODIFF_SCALAR_H bool operator==(const Scalar &other) const
static void run(A &a, B &b)
AutoDiffScalar(const Scalar &value, int nbDer, int derNumber)
return ReturnType(abs2(x.value()), x.derivatives()*(Scalar(2)*x.value()))
USING_NAMESPACE_ACADO IntermediateState sin(const Expression &arg)
friend const AutoDiffScalar< CwiseUnaryOp< internal::scalar_opposite_op< Scalar >, const DerType > > operator-(const Scalar &a, const AutoDiffScalar &b)
ExportIndex operator+(const ExportIndex &_arg1, const ExportIndex &_arg2)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_pow_op< typename Derived::Scalar >, const Derived > pow(const Eigen::ArrayBase< Derived > &x, const typename Derived::Scalar &exponent)
const AutoDiffScalar< typename CwiseUnaryOp< scalar_multiple2_op< Scalar, Real >, DerType >::Type > operator*(const Real &other) const
AutoDiffScalar & operator*=(const AutoDiffScalar< OtherDerType > &other)
const AutoDiffScalar< DerType > & conj(const AutoDiffScalar< DerType > &x)
IntermediateState sqrt(const Expression &arg)
EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(abs, using std::abs;return ReturnType(abs(x.value()), x.derivatives()*(x.value()< 0?-1:1));) EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(abs2
internal::remove_all< _DerType >::type DerType
internal::auto_diff_special_op< _DerType,!internal::is_same< typename internal::traits< typename internal::remove_all< _DerType >::type >::Scalar, typename NumTraits< typename internal::traits< typename internal::remove_all< _DerType >::type >::Scalar >::Real >::value > Base
const AutoDiffScalar< CwiseUnaryOp< internal::scalar_multiple_op< Scalar >, const CwiseBinaryOp< internal::scalar_difference_op< Scalar >, const CwiseUnaryOp< internal::scalar_multiple_op< Scalar >, const DerType >, const CwiseUnaryOp< internal::scalar_multiple_op< Scalar >, const typename internal::remove_all< OtherDerType >::type > > > > operator/(const AutoDiffScalar< OtherDerType > &other) const
USING_NAMESPACE_ACADO typedef TaylorVariable< Interval > T
Matrix< A_Scalar, A_Rows, A_Cols, A_Options, A_MaxRows, A_MaxCols > A
A scalar type replacement with automatic differentation capability.
const AutoDiffScalar< Matrix< typename internal::traits< DerTypeA >::Scalar, Dynamic, 1 > > atan2(const AutoDiffScalar< DerTypeA > &a, const AutoDiffScalar< DerTypeB > &b)
AutoDiffScalar & operator+=(const AutoDiffScalar< OtherDerType > &other)
void make_coherent(const A &a, const B &b)
friend const AutoDiffScalar< CwiseUnaryOp< internal::scalar_multiple_op< Scalar >, const DerType > > operator/(const Scalar &other, const AutoDiffScalar &a)
Matrix< A_Scalar, A_Rows, A_Cols, A_Options, A_MaxRows, A_MaxCols > ReturnType
Eigen::internal::make_coherent_impl< Matrix< A_Scalar, A_Rows, A_Cols, A_Options, A_MaxRows, A_MaxCols >, Matrix< B_Scalar, B_Rows, B_Cols, B_Options, B_MaxRows, B_MaxCols > >::run static void run(A &a, B &b)
iterative scaling algorithm to equilibrate rows and column norms in matrices
DerType::Scalar imag(const AutoDiffScalar< DerType > &)
IntermediateState asin(const Expression &arg)
IntermediateState pow(const Expression &arg1, const Expression &arg2)
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
const internal::permut_matrix_product_retval< PermutationDerived, Derived, OnTheRight > operator*(const MatrixBase< Derived > &matrix, const PermutationBase< PermutationDerived > &permutation)
AutoDiffScalar< _DerType > & operator+=(const Real &other)
IntermediateState tan(const Expression &arg)
const AutoDiffScalar< DerType & > operator+(const Real &other) const
AutoDiffScalar(const AutoDiffScalar< OtherDerType > &other)
const AutoDiffScalar< CwiseBinaryOp< internal::scalar_difference_op< Scalar >, const DerType, const typename internal::remove_all< OtherDerType >::type > > operator-(const AutoDiffScalar< OtherDerType > &other) const
EIGEN_STRONG_INLINE const CwiseUnaryOp< internal::scalar_abs2_op< Scalar >, const Derived > abs2() const
AutoDiffScalar & operator-=(const AutoDiffScalar< OtherDerType > &other)
friend bool operator!=(const Scalar &a, const AutoDiffScalar &b)
const AutoDiffScalar< DerType & > operator+(const Scalar &other) const
IntermediateState cos(const Expression &arg)
EIGEN_STRONG_INLINE const CwiseUnaryOp< internal::scalar_abs_op< Scalar >, const Derived > abs() const
traits< DerType >::Scalar Scalar
friend const AutoDiffScalar< DerType & > operator+(const Real &a, const AutoDiffScalar< _DerType > &b)
Generic expression where a coefficient-wise binary operator is applied to two expressions.
AutoDiffScalar & operator/=(const Scalar &other)
NumTraits< Scalar >::Real Real
AutoDiffScalar & operator=(const AutoDiffScalar &other)
Eigen::internal::make_coherent_impl< Matrix< A_Scalar, A_Rows, A_Cols, A_Options, A_MaxRows, A_MaxCols >, Matrix< B_Scalar, B_Rows, B_Cols, B_Options, B_MaxRows, B_MaxCols > >::A Matrix< A_Scalar, A_Rows, A_Cols, A_Options, A_MaxRows, A_MaxCols > A
Eigen::internal::make_coherent_impl< Matrix< A_Scalar, A_Rows, A_Cols, A_Options, A_MaxRows, A_MaxCols >, Matrix< B_Scalar, B_Rows, B_Cols, B_Options, B_MaxRows, B_MaxCols > >::B Matrix< B_Scalar, B_Rows, B_Cols, B_Options, B_MaxRows, B_MaxCols > B
const AutoDiffScalar< DerType & > operator-(const Scalar &b) const
IntermediateState acos(const Expression &arg)
EIGEN_STRONG_INLINE void resize(Index nbRows, Index nbCols)
static void run(A &, B &)
remove_all< _DerType >::type DerType
const AutoDiffScalar< CwiseBinaryOp< internal::scalar_sum_op< Scalar >, const CwiseUnaryOp< internal::scalar_multiple_op< Scalar >, const DerType >, const CwiseUnaryOp< internal::scalar_multiple_op< Scalar >, const typename internal::remove_all< OtherDerType >::type > > > operator*(const AutoDiffScalar< OtherDerType > &other) const
bool operator<=(const Scalar &other) const
internal::traits< DerType >::Scalar Scalar
friend const AutoDiffScalar< typename CwiseUnaryOp< scalar_multiple2_op< Scalar, Real >, DerType >::Type > operator*(const Real &other, const AutoDiffScalar< _DerType > &a)
AutoDiffScalar(const Real &value)
Matrix< A_Scalar, A_Rows, A_Cols, A_Options, A_MaxRows, A_MaxCols > ReturnType
AutoDiffScalar< _DerType > & operator*=(const Scalar &other)
bool operator!=(const AutoDiffScalar< OtherDerType > &b) const
friend bool operator<=(const Scalar &a, const AutoDiffScalar &b)
NumTraits< Scalar >::Real Real
Derived & setZero(Index size)
ExportStatementBlock & operator<<(ExportStatementBlock &_block, const ExportStatement &_statement)
const AutoDiffScalar< CwiseUnaryOp< internal::scalar_multiple_op< Scalar >, const DerType > > operator*(const Scalar &other) const
const AutoDiffScalar< _DerType > & derived() const
friend const AutoDiffScalar< DerType & > operator+(const Scalar &a, const AutoDiffScalar &b)
const AutoDiffScalar< CwiseUnaryOp< internal::scalar_opposite_op< Scalar >, const DerType > > operator-() const
bool operator>=(const Scalar &other) const
ExportIndex operator-(const ExportIndex &_arg1, const ExportIndex &_arg2)
AutoDiffScalar & operator=(const AutoDiffScalar< OtherDerType > &other)
friend bool operator==(const Scalar &a, const AutoDiffScalar &b)
const DerType & derivatives() const
const AutoDiffScalar< CwiseBinaryOp< internal::scalar_sum_op< Scalar >, const DerType, const typename internal::remove_all< OtherDerType >::type > > operator+(const AutoDiffScalar< OtherDerType > &other) const
AutoDiffScalar< DerType > ReturnType
friend const AutoDiffScalar< CwiseUnaryOp< internal::scalar_multiple_op< Scalar >, const DerType > > operator*(const Scalar &other, const AutoDiffScalar &a)
bool operator>=(const AutoDiffScalar< OtherDerType > &b) const
AutoDiffScalar & operator-=(const Scalar &other)
const Scalar & value() const
bool operator==(const AutoDiffScalar< OtherDerType > &b) const
IntermediateState exp(const Expression &arg)
AutoDiffScalar< DerType > ReturnType
Matrix< B_Scalar, B_Rows, B_Cols, B_Options, B_MaxRows, B_MaxCols > B
AutoDiffScalar(const Scalar &value, const DerType &der)
static void run(A &a, B &b)
Generic expression where a coefficient-wise unary operator is applied to an expression.
const AutoDiffScalar< CwiseUnaryOp< internal::scalar_multiple_op< Scalar >, const DerType > > operator/(const Scalar &other) const
AutoDiffScalar & operator+=(const Scalar &other)
AutoDiffScalar< _DerType > & derived()
The matrix class, also used for vectors and row-vectors.
AutoDiffScalar(const AutoDiffScalar &other)
bool operator!=(const Scalar &other) const
const AutoDiffScalar< DerType > & real(const AutoDiffScalar< DerType > &x)
AutoDiffScalar & operator/=(const AutoDiffScalar< OtherDerType > &other)
friend bool operator>=(const Scalar &a, const AutoDiffScalar &b)
AutoDiffScalar & operator*=(const Scalar &other)
IntermediateState log(const Expression &arg)