Eigen::AutoDiffScalar< DerivativeType > Class Template Reference

A scalar type replacement with automatic differentiation capability. More...

Inherits Eigen::internal::auto_diff_special_op< DerivativeType, !internal::is_same< internal::traits< internal::remove_all_t< DerivativeType > >::Scalar, NumTraits< internal::traits< internal::remove_all_t< DerivativeType > >::Scalar >::Real >::value >.

Public Types

typedef internal::auto_diff_special_op< DerivativeType, !internal::is_same< typename internal::traits< internal::remove_all_t< DerivativeType > >::Scalar, typename NumTraits< typename internal::traits< internal::remove_all_t< DerivativeType > >::Scalar >::Real >::valueBase
 
typedef internal::remove_all_t< DerivativeType > DerType
 
typedef NumTraits< Scalar >::Real Real
 
typedef internal::traits< DerType >::Scalar Scalar
 

Public Member Functions

 AutoDiffScalar ()
 
 AutoDiffScalar (const AutoDiffScalar &other)
 
template<typename OtherDerType >
 AutoDiffScalar (const AutoDiffScalar< OtherDerType > &other)
 
 AutoDiffScalar (const Real &value)
 
 AutoDiffScalar (const Scalar &value, const DerType &der)
 
 AutoDiffScalar (const Scalar &value, int nbDer, int derNumber)
 
DerTypederivatives ()
 
const DerTypederivatives () const
 
template<typename OtherDerType >
bool operator!= (const AutoDiffScalar< OtherDerType > &b) const
 
bool operator!= (const Scalar &other) const
 
template<typename OtherDerType >
AutoDiffScalar< CwiseBinaryOp< internal::scalar_sum_op< Scalar >, const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(DerType, Scalar, product), const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(internal::remove_all_t< OtherDerType >, Scalar, product) > > operator* (const AutoDiffScalar< OtherDerType > &other) const
 
AutoDiffScalar< EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(DerType, Scalar, product) > operator* (const Scalar &other) const
 
template<typename OtherDerType >
AutoDiffScalaroperator*= (const AutoDiffScalar< OtherDerType > &other)
 
AutoDiffScalaroperator*= (const Scalar &other)
 
template<typename OtherDerType >
AutoDiffScalar< CwiseBinaryOp< internal::scalar_sum_op< Scalar >, const DerType, const internal::remove_all_t< OtherDerType > > > operator+ (const AutoDiffScalar< OtherDerType > &other) const
 
AutoDiffScalar< DerType & > operator+ (const Scalar &other) const
 
template<typename OtherDerType >
AutoDiffScalaroperator+= (const AutoDiffScalar< OtherDerType > &other)
 
AutoDiffScalaroperator+= (const Scalar &other)
 
AutoDiffScalar< CwiseUnaryOp< internal::scalar_opposite_op< Scalar >, const DerType > > operator- () const
 
template<typename OtherDerType >
AutoDiffScalar< CwiseBinaryOp< internal::scalar_difference_op< Scalar >, const DerType, const internal::remove_all_t< OtherDerType > > > operator- (const AutoDiffScalar< OtherDerType > &other) const
 
AutoDiffScalar< DerType & > operator- (const Scalar &b) const
 
template<typename OtherDerType >
AutoDiffScalaroperator-= (const AutoDiffScalar< OtherDerType > &other)
 
AutoDiffScalaroperator-= (const Scalar &other)
 
template<typename OtherDerType >
AutoDiffScalar< EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(CwiseBinaryOp< internal::scalar_difference_op< Scalar > EIGEN_COMMA const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(DerType, Scalar, product) EIGEN_COMMA const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(internal::remove_all_t< OtherDerType >, Scalar, product) >, Scalar, product) > operator/ (const AutoDiffScalar< OtherDerType > &other) const
 
AutoDiffScalar< EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(DerType, Scalar, product) > operator/ (const Scalar &other) const
 
template<typename OtherDerType >
AutoDiffScalaroperator/= (const AutoDiffScalar< OtherDerType > &other)
 
AutoDiffScalaroperator/= (const Scalar &other)
 
template<typename OtherDerType >
bool operator< (const AutoDiffScalar< OtherDerType > &b) const
 
bool operator< (const Scalar &other) const
 
template<typename OtherDerType >
bool operator<= (const AutoDiffScalar< OtherDerType > &b) const
 
bool operator<= (const Scalar &other) const
 
AutoDiffScalaroperator= (const AutoDiffScalar &other)
 
template<typename OtherDerType >
AutoDiffScalaroperator= (const AutoDiffScalar< OtherDerType > &other)
 
AutoDiffScalaroperator= (const Scalar &other)
 
template<typename OtherDerType >
bool operator== (const AutoDiffScalar< OtherDerType > &b) const
 
bool operator== (const Scalar &other) const
 
template<typename OtherDerType >
bool operator> (const AutoDiffScalar< OtherDerType > &b) const
 
bool operator> (const Scalar &other) const
 
template<typename OtherDerType >
bool operator>= (const AutoDiffScalar< OtherDerType > &b) const
 
bool operator>= (const Scalar &other) const
 
Scalarvalue ()
 
const Scalarvalue () const
 

Protected Attributes

DerType m_derivatives
 
Scalar m_value
 

Detailed Description

template<typename DerivativeType>
class Eigen::AutoDiffScalar< DerivativeType >

A scalar type replacement with automatic differentiation capability.

Parameters
DerivativeTypethe vector type used to store/represent the derivatives. The base scalar type as well as the number of derivatives to compute are determined from this type. Typical choices include, e.g., Vector4f for 4 derivatives, or VectorXf if the number of derivatives is not known at compile time, and/or, the number of derivatives is large. Note that DerivativeType can also be a reference (e.g., VectorXf&) to wrap a existing vector into an AutoDiffScalar. Finally, DerivativeType can also be any Eigen compatible expression.

This class represents a scalar value while tracking its respective derivatives using Eigen's expression template mechanism.

It supports the following list of global math function:

  • std::abs, std::sqrt, std::pow, std::exp, std::log, std::sin, std::cos,
  • internal::abs, internal::sqrt, numext::pow, internal::exp, internal::log, internal::sin, internal::cos,
  • internal::conj, internal::real, internal::imag, numext::abs2.

AutoDiffScalar can be used as the scalar type of an Eigen::Matrix object. However, in that case, the expression template mechanism only occurs at the top Matrix level, while derivatives are computed right away.

Definition at line 69 of file AutoDiffScalar.h.

Member Typedef Documentation

◆ Base

template<typename DerivativeType >
typedef internal::auto_diff_special_op<DerivativeType, !internal::is_same<typename internal::traits<internal::remove_all_t<DerivativeType> >::Scalar, typename NumTraits<typename internal::traits<internal::remove_all_t<DerivativeType> >::Scalar>::Real>::value> Eigen::AutoDiffScalar< DerivativeType >::Base

Definition at line 77 of file AutoDiffScalar.h.

◆ DerType

template<typename DerivativeType >
typedef internal::remove_all_t<DerivativeType> Eigen::AutoDiffScalar< DerivativeType >::DerType

Definition at line 78 of file AutoDiffScalar.h.

◆ Real

template<typename DerivativeType >
typedef NumTraits<Scalar>::Real Eigen::AutoDiffScalar< DerivativeType >::Real

Definition at line 80 of file AutoDiffScalar.h.

◆ Scalar

template<typename DerivativeType >
typedef internal::traits<DerType>::Scalar Eigen::AutoDiffScalar< DerivativeType >::Scalar

Definition at line 79 of file AutoDiffScalar.h.

Constructor & Destructor Documentation

◆ AutoDiffScalar() [1/6]

template<typename DerivativeType >
Eigen::AutoDiffScalar< DerivativeType >::AutoDiffScalar ( )
inline

Default constructor without any initialization.

Definition at line 86 of file AutoDiffScalar.h.

86 {}

◆ AutoDiffScalar() [2/6]

template<typename DerivativeType >
Eigen::AutoDiffScalar< DerivativeType >::AutoDiffScalar ( const Scalar value,
int  nbDer,
int  derNumber 
)
inline

Constructs an active scalar from its value, and initializes the nbDer derivatives such that it corresponds to the derNumber -th variable

Definition at line 90 of file AutoDiffScalar.h.

91  : m_value(value), m_derivatives(DerType::Zero(nbDer))
92  {
93  m_derivatives.coeffRef(derNumber) = Scalar(1);
94  }
internal::traits< DerType >::Scalar Scalar
const Scalar & value() const

◆ AutoDiffScalar() [3/6]

template<typename DerivativeType >
Eigen::AutoDiffScalar< DerivativeType >::AutoDiffScalar ( const Real value)
inline

Conversion from a scalar constant to an active scalar. The derivatives are set to zero.

Definition at line 98 of file AutoDiffScalar.h.

99  : m_value(value)
100  {
101  if(m_derivatives.size()>0)
102  m_derivatives.setZero();
103  }

◆ AutoDiffScalar() [4/6]

template<typename DerivativeType >
Eigen::AutoDiffScalar< DerivativeType >::AutoDiffScalar ( const Scalar value,
const DerType der 
)
inline

Constructs an active scalar from its value and derivatives der

Definition at line 106 of file AutoDiffScalar.h.

107  : m_value(value), m_derivatives(der)
108  {}

◆ AutoDiffScalar() [5/6]

template<typename DerivativeType >
template<typename OtherDerType >
Eigen::AutoDiffScalar< DerivativeType >::AutoDiffScalar ( const AutoDiffScalar< OtherDerType > &  other)
inline

Definition at line 111 of file AutoDiffScalar.h.

118  : m_value(other.value()), m_derivatives(other.derivatives())
119  {}
const DerType & derivatives() const

◆ AutoDiffScalar() [6/6]

template<typename DerivativeType >
Eigen::AutoDiffScalar< DerivativeType >::AutoDiffScalar ( const AutoDiffScalar< DerivativeType > &  other)
inline

Definition at line 126 of file AutoDiffScalar.h.

127  : m_value(other.value()), m_derivatives(other.derivatives())
128  {}

Member Function Documentation

◆ derivatives() [1/2]

template<typename DerivativeType >
DerType& Eigen::AutoDiffScalar< DerivativeType >::derivatives ( )
inline

Definition at line 160 of file AutoDiffScalar.h.

160 { return m_derivatives; }

◆ derivatives() [2/2]

template<typename DerivativeType >
const DerType& Eigen::AutoDiffScalar< DerivativeType >::derivatives ( ) const
inline

Definition at line 159 of file AutoDiffScalar.h.

159 { return m_derivatives; }

◆ operator!=() [1/2]

template<typename DerivativeType >
template<typename OtherDerType >
bool Eigen::AutoDiffScalar< DerivativeType >::operator!= ( const AutoDiffScalar< OtherDerType > &  b) const
inline

Definition at line 181 of file AutoDiffScalar.h.

181 { return m_value != b.value(); }

◆ operator!=() [2/2]

template<typename DerivativeType >
bool Eigen::AutoDiffScalar< DerivativeType >::operator!= ( const Scalar other) const
inline

Definition at line 167 of file AutoDiffScalar.h.

167 { return m_value != other; }

◆ operator*() [1/2]

template<typename DerivativeType >
template<typename OtherDerType >
AutoDiffScalar<CwiseBinaryOp<internal::scalar_sum_op<Scalar>, const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(DerType,Scalar,product), const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(internal::remove_all_t<OtherDerType>,Scalar,product) > > Eigen::AutoDiffScalar< DerivativeType >::operator* ( const AutoDiffScalar< OtherDerType > &  other) const
inline

Definition at line 345 of file AutoDiffScalar.h.

346  {
348  return MakeAutoDiffScalar(
349  m_value * other.value(),
350  (m_derivatives * other.value()) + (other.derivatives() * m_value));
351  }
void make_coherent(const A &a, const B &b)
AutoDiffScalar< NewDerType > MakeAutoDiffScalar(const typename NewDerType::Scalar &value, const NewDerType &der)

◆ operator*() [2/2]

template<typename DerivativeType >
AutoDiffScalar<EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(DerType,Scalar,product) > Eigen::AutoDiffScalar< DerivativeType >::operator* ( const Scalar other) const
inline

Definition at line 272 of file AutoDiffScalar.h.

273  {
274  return MakeAutoDiffScalar(m_value * other, m_derivatives * other);
275  }

◆ operator*=() [1/2]

template<typename DerivativeType >
template<typename OtherDerType >
AutoDiffScalar& Eigen::AutoDiffScalar< DerivativeType >::operator*= ( const AutoDiffScalar< OtherDerType > &  other)
inline

Definition at line 360 of file AutoDiffScalar.h.

361  {
362  *this = *this * other;
363  return *this;
364  }

◆ operator*=() [2/2]

template<typename DerivativeType >
AutoDiffScalar& Eigen::AutoDiffScalar< DerivativeType >::operator*= ( const Scalar other)
inline

Definition at line 353 of file AutoDiffScalar.h.

354  {
355  *this = *this * other;
356  return *this;
357  }

◆ operator+() [1/2]

template<typename DerivativeType >
template<typename OtherDerType >
AutoDiffScalar<CwiseBinaryOp<internal::scalar_sum_op<Scalar>,const DerType,const internal::remove_all_t<OtherDerType> > > Eigen::AutoDiffScalar< DerivativeType >::operator+ ( const AutoDiffScalar< OtherDerType > &  other) const
inline

Definition at line 211 of file AutoDiffScalar.h.

212  {
214  return AutoDiffScalar<CwiseBinaryOp<internal::scalar_sum_op<Scalar>,const DerType,const internal::remove_all_t<OtherDerType>> >(
215  m_value + other.value(),
216  m_derivatives + other.derivatives());
217  }
A scalar type replacement with automatic differentiation capability.
internal::remove_all_t< DerivativeType > DerType

◆ operator+() [2/2]

template<typename DerivativeType >
AutoDiffScalar<DerType&> Eigen::AutoDiffScalar< DerivativeType >::operator+ ( const Scalar other) const
inline

Definition at line 183 of file AutoDiffScalar.h.

184  {
186  }

◆ operator+=() [1/2]

template<typename DerivativeType >
template<typename OtherDerType >
AutoDiffScalar& Eigen::AutoDiffScalar< DerivativeType >::operator+= ( const AutoDiffScalar< OtherDerType > &  other)
inline

Definition at line 221 of file AutoDiffScalar.h.

222  {
223  (*this) = (*this) + other;
224  return *this;
225  }

◆ operator+=() [2/2]

template<typename DerivativeType >
AutoDiffScalar& Eigen::AutoDiffScalar< DerivativeType >::operator+= ( const Scalar other)
inline

Definition at line 203 of file AutoDiffScalar.h.

204  {
205  value() += other;
206  return *this;
207  }

◆ operator-() [1/3]

template<typename DerivativeType >
AutoDiffScalar<CwiseUnaryOp<internal::scalar_opposite_op<Scalar>, const DerType> > Eigen::AutoDiffScalar< DerivativeType >::operator- ( ) const
inline

Definition at line 264 of file AutoDiffScalar.h.

265  {
267  -m_value,
268  -m_derivatives);
269  }

◆ operator-() [2/3]

template<typename DerivativeType >
template<typename OtherDerType >
AutoDiffScalar<CwiseBinaryOp<internal::scalar_difference_op<Scalar>, const DerType,const internal::remove_all_t<OtherDerType> > > Eigen::AutoDiffScalar< DerivativeType >::operator- ( const AutoDiffScalar< OtherDerType > &  other) const
inline

Definition at line 247 of file AutoDiffScalar.h.

248  {
250  return AutoDiffScalar<CwiseBinaryOp<internal::scalar_difference_op<Scalar>, const DerType,const internal::remove_all_t<OtherDerType>> >(
251  m_value - other.value(),
252  m_derivatives - other.derivatives());
253  }

◆ operator-() [3/3]

template<typename DerivativeType >
AutoDiffScalar<DerType&> Eigen::AutoDiffScalar< DerivativeType >::operator- ( const Scalar b) const
inline

Definition at line 227 of file AutoDiffScalar.h.

228  {
230  }

◆ operator-=() [1/2]

template<typename DerivativeType >
template<typename OtherDerType >
AutoDiffScalar& Eigen::AutoDiffScalar< DerivativeType >::operator-= ( const AutoDiffScalar< OtherDerType > &  other)
inline

Definition at line 257 of file AutoDiffScalar.h.

258  {
259  *this = *this - other;
260  return *this;
261  }

◆ operator-=() [2/2]

template<typename DerivativeType >
AutoDiffScalar& Eigen::AutoDiffScalar< DerivativeType >::operator-= ( const Scalar other)
inline

Definition at line 239 of file AutoDiffScalar.h.

240  {
241  value() -= other;
242  return *this;
243  }

◆ operator/() [1/2]

template<typename DerivativeType >
template<typename OtherDerType >
AutoDiffScalar<EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE( CwiseBinaryOp<internal::scalar_difference_op<Scalar> EIGEN_COMMA const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(DerType,Scalar,product) EIGEN_COMMA const EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(internal::remove_all_t<OtherDerType>,Scalar,product) >,Scalar,product) > Eigen::AutoDiffScalar< DerivativeType >::operator/ ( const AutoDiffScalar< OtherDerType > &  other) const
inline

Definition at line 332 of file AutoDiffScalar.h.

333  {
335  return MakeAutoDiffScalar(
336  m_value / other.value(),
337  ((m_derivatives * other.value()) - (other.derivatives() * m_value))
338  * (Scalar(1)/(other.value()*other.value())));
339  }

◆ operator/() [2/2]

template<typename DerivativeType >
AutoDiffScalar<EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(DerType,Scalar,product) > Eigen::AutoDiffScalar< DerivativeType >::operator/ ( const Scalar other) const
inline

Definition at line 300 of file AutoDiffScalar.h.

301  {
302  return MakeAutoDiffScalar(m_value / other, (m_derivatives * (Scalar(1)/other)));
303  }

◆ operator/=() [1/2]

template<typename DerivativeType >
template<typename OtherDerType >
AutoDiffScalar& Eigen::AutoDiffScalar< DerivativeType >::operator/= ( const AutoDiffScalar< OtherDerType > &  other)
inline

Definition at line 373 of file AutoDiffScalar.h.

374  {
375  *this = *this / other;
376  return *this;
377  }

◆ operator/=() [2/2]

template<typename DerivativeType >
AutoDiffScalar& Eigen::AutoDiffScalar< DerivativeType >::operator/= ( const Scalar other)
inline

Definition at line 366 of file AutoDiffScalar.h.

367  {
368  *this = *this / other;
369  return *this;
370  }

◆ operator<() [1/2]

template<typename DerivativeType >
template<typename OtherDerType >
bool Eigen::AutoDiffScalar< DerivativeType >::operator< ( const AutoDiffScalar< OtherDerType > &  b) const
inline

Definition at line 176 of file AutoDiffScalar.h.

176 { return m_value < b.value(); }

◆ operator<() [2/2]

template<typename DerivativeType >
bool Eigen::AutoDiffScalar< DerivativeType >::operator< ( const Scalar other) const
inline

Definition at line 162 of file AutoDiffScalar.h.

162 { return m_value < other; }

◆ operator<=() [1/2]

template<typename DerivativeType >
template<typename OtherDerType >
bool Eigen::AutoDiffScalar< DerivativeType >::operator<= ( const AutoDiffScalar< OtherDerType > &  b) const
inline

Definition at line 177 of file AutoDiffScalar.h.

177 { return m_value <= b.value(); }

◆ operator<=() [2/2]

template<typename DerivativeType >
bool Eigen::AutoDiffScalar< DerivativeType >::operator<= ( const Scalar other) const
inline

Definition at line 163 of file AutoDiffScalar.h.

163 { return m_value <= other; }

◆ operator=() [1/3]

template<typename DerivativeType >
AutoDiffScalar& Eigen::AutoDiffScalar< DerivativeType >::operator= ( const AutoDiffScalar< DerivativeType > &  other)
inline

Definition at line 138 of file AutoDiffScalar.h.

139  {
140  m_value = other.value();
141  m_derivatives = other.derivatives();
142  return *this;
143  }

◆ operator=() [2/3]

template<typename DerivativeType >
template<typename OtherDerType >
AutoDiffScalar& Eigen::AutoDiffScalar< DerivativeType >::operator= ( const AutoDiffScalar< OtherDerType > &  other)
inline

Definition at line 131 of file AutoDiffScalar.h.

132  {
133  m_value = other.value();
134  m_derivatives = other.derivatives();
135  return *this;
136  }

◆ operator=() [3/3]

template<typename DerivativeType >
AutoDiffScalar& Eigen::AutoDiffScalar< DerivativeType >::operator= ( const Scalar other)
inline

Definition at line 145 of file AutoDiffScalar.h.

146  {
147  m_value = other;
148  if(m_derivatives.size()>0)
149  m_derivatives.setZero();
150  return *this;
151  }

◆ operator==() [1/2]

template<typename DerivativeType >
template<typename OtherDerType >
bool Eigen::AutoDiffScalar< DerivativeType >::operator== ( const AutoDiffScalar< OtherDerType > &  b) const
inline

Definition at line 180 of file AutoDiffScalar.h.

180 { return m_value == b.value(); }

◆ operator==() [2/2]

template<typename DerivativeType >
bool Eigen::AutoDiffScalar< DerivativeType >::operator== ( const Scalar other) const
inline

Definition at line 166 of file AutoDiffScalar.h.

166 { return m_value == other; }

◆ operator>() [1/2]

template<typename DerivativeType >
template<typename OtherDerType >
bool Eigen::AutoDiffScalar< DerivativeType >::operator> ( const AutoDiffScalar< OtherDerType > &  b) const
inline

Definition at line 178 of file AutoDiffScalar.h.

178 { return m_value > b.value(); }

◆ operator>() [2/2]

template<typename DerivativeType >
bool Eigen::AutoDiffScalar< DerivativeType >::operator> ( const Scalar other) const
inline

Definition at line 164 of file AutoDiffScalar.h.

164 { return m_value > other; }

◆ operator>=() [1/2]

template<typename DerivativeType >
template<typename OtherDerType >
bool Eigen::AutoDiffScalar< DerivativeType >::operator>= ( const AutoDiffScalar< OtherDerType > &  b) const
inline

Definition at line 179 of file AutoDiffScalar.h.

179 { return m_value >= b.value(); }

◆ operator>=() [2/2]

template<typename DerivativeType >
bool Eigen::AutoDiffScalar< DerivativeType >::operator>= ( const Scalar other) const
inline

Definition at line 165 of file AutoDiffScalar.h.

165 { return m_value >= other; }

◆ value() [1/2]

template<typename DerivativeType >
Scalar& Eigen::AutoDiffScalar< DerivativeType >::value ( )
inline

Definition at line 157 of file AutoDiffScalar.h.

157 { return m_value; }

◆ value() [2/2]

template<typename DerivativeType >
const Scalar& Eigen::AutoDiffScalar< DerivativeType >::value ( ) const
inline

Definition at line 156 of file AutoDiffScalar.h.

156 { return m_value; }

Member Data Documentation

◆ m_derivatives

template<typename DerivativeType >
DerType Eigen::AutoDiffScalar< DerivativeType >::m_derivatives
protected

Definition at line 381 of file AutoDiffScalar.h.

◆ m_value

template<typename DerivativeType >
Scalar Eigen::AutoDiffScalar< DerivativeType >::m_value
protected

Definition at line 380 of file AutoDiffScalar.h.


The documentation for this class was generated from the following file: