Eigen::AutoDiffScalar< DerivativeType > Class Template Reference

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

#include <AutoDiffScalar.h>

+ Inheritance diagram for Eigen::AutoDiffScalar< DerivativeType >:

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 internal::traits< DerType >::Scalar Scalar
 
typedef NumTraits< Scalar >::Real Real
 

Public Member Functions

 AutoDiffScalar ()
 
 AutoDiffScalar (const Scalar &value, int nbDer, int derNumber)
 
 AutoDiffScalar (const Real &value)
 
 AutoDiffScalar (const Scalar &value, const DerType &der)
 
template<typename OtherDerType >
 AutoDiffScalar (const AutoDiffScalar< OtherDerType > &other, std::enable_if_t< internal::is_same< Scalar, typename internal::traits< internal::remove_all_t< OtherDerType >>::Scalar >::value &&internal::is_convertible< OtherDerType, DerType >::value, void * >=0)
 
 AutoDiffScalar (const AutoDiffScalar &other)
 
template<typename OtherDerType >
AutoDiffScalaroperator= (const AutoDiffScalar< OtherDerType > &other)
 
AutoDiffScalaroperator= (const AutoDiffScalar &other)
 
AutoDiffScalaroperator= (const Scalar &other)
 
const Scalarvalue () const
 
Scalarvalue ()
 
const DerTypederivatives () const
 
DerTypederivatives ()
 
bool operator< (const Scalar &other) const
 
bool operator<= (const Scalar &other) const
 
bool operator> (const Scalar &other) const
 
bool operator>= (const Scalar &other) const
 
bool operator== (const Scalar &other) const
 
bool operator!= (const Scalar &other) const
 
template<typename OtherDerType >
bool operator< (const AutoDiffScalar< OtherDerType > &b) const
 
template<typename OtherDerType >
bool operator<= (const AutoDiffScalar< OtherDerType > &b) const
 
template<typename OtherDerType >
bool operator> (const AutoDiffScalar< OtherDerType > &b) const
 
template<typename OtherDerType >
bool operator>= (const AutoDiffScalar< OtherDerType > &b) const
 
template<typename OtherDerType >
bool operator== (const AutoDiffScalar< OtherDerType > &b) const
 
template<typename OtherDerType >
bool operator!= (const AutoDiffScalar< OtherDerType > &b) const
 
AutoDiffScalar< DerType & > operator+ (const Scalar &other) const
 
AutoDiffScalaroperator+= (const Scalar &other)
 
template<typename OtherDerType >
auto operator+ (const AutoDiffScalar< OtherDerType > &other) const
 
template<typename OtherDerType >
AutoDiffScalaroperator+= (const AutoDiffScalar< OtherDerType > &other)
 
AutoDiffScalar< DerType & > operator- (const Scalar &b) const
 
AutoDiffScalaroperator-= (const Scalar &other)
 
template<typename OtherDerType >
auto operator- (const AutoDiffScalar< OtherDerType > &other) const
 
template<typename OtherDerType >
AutoDiffScalaroperator-= (const AutoDiffScalar< OtherDerType > &other)
 
AutoDiffScalar< CwiseUnaryOp< internal::scalar_opposite_op< Scalar >, const DerType > > operator- () const
 
auto operator* (const Scalar &other) const
 
auto operator/ (const Scalar &other) const
 
template<typename OtherDerType >
auto operator/ (const AutoDiffScalar< OtherDerType > &other) const
 
template<typename OtherDerType >
auto operator* (const AutoDiffScalar< OtherDerType > &other) const
 
AutoDiffScalaroperator*= (const Scalar &other)
 
template<typename OtherDerType >
AutoDiffScalaroperator*= (const AutoDiffScalar< OtherDerType > &other)
 
AutoDiffScalaroperator/= (const Scalar &other)
 
template<typename OtherDerType >
AutoDiffScalaroperator/= (const AutoDiffScalar< OtherDerType > &other)
 

Protected Attributes

Scalar m_value
 
DerType m_derivatives
 

Friends

std::ostream & operator<< (std::ostream &s, const AutoDiffScalar &a)
 
bool operator< (const Scalar &a, const AutoDiffScalar &b)
 
bool operator<= (const Scalar &a, const AutoDiffScalar &b)
 
bool operator> (const Scalar &a, const AutoDiffScalar &b)
 
bool operator>= (const Scalar &a, const AutoDiffScalar &b)
 
bool operator== (const Scalar &a, const AutoDiffScalar &b)
 
bool operator!= (const Scalar &a, const AutoDiffScalar &b)
 
AutoDiffScalar< DerType & > operator+ (const Scalar &a, const AutoDiffScalar &b)
 
AutoDiffScalar< CwiseUnaryOp< internal::scalar_opposite_op< Scalar >, const DerType > > operator- (const Scalar &a, const AutoDiffScalar &b)
 
auto operator* (const Scalar &other, const AutoDiffScalar &a)
 
auto operator/ (const Scalar &other, const AutoDiffScalar &a)
 

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.

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

◆ DerType

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

◆ Real

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

◆ Scalar

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

Constructor & Destructor Documentation

◆ AutoDiffScalar() [1/6]

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

Default constructor without any initialization.

115 {}

◆ 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

120  m_derivatives.coeffRef(derNumber) = Scalar(1);
121  }
internal::traits< DerType >::Scalar Scalar
Definition: AutoDiffScalar.h:108
const Scalar & value() const
Definition: AutoDiffScalar.h:172
Scalar m_value
Definition: AutoDiffScalar.h:371
DerType m_derivatives
Definition: AutoDiffScalar.h:372
double Zero
Definition: pseudosolid_node_update_elements.cc:35

References Eigen::AutoDiffScalar< DerivativeType >::m_derivatives.

◆ 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.

125  : m_value(value) {
126  if (m_derivatives.size() > 0) m_derivatives.setZero();
127  }

References Eigen::AutoDiffScalar< DerivativeType >::m_derivatives.

◆ 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

130 : m_value(value), m_derivatives(der) {}

◆ AutoDiffScalar() [5/6]

template<typename DerivativeType >
template<typename OtherDerType >
Eigen::AutoDiffScalar< DerivativeType >::AutoDiffScalar ( const AutoDiffScalar< OtherDerType > &  other,
std::enable_if_t< internal::is_same< Scalar, typename internal::traits< internal::remove_all_t< OtherDerType >>::Scalar >::value &&internal::is_convertible< OtherDerType, DerType >::value, void * >  = 0 
)
inline
143  : m_value(other.value()), m_derivatives(other.derivatives()) {
144  }
const DerType & derivatives() const
Definition: AutoDiffScalar.h:175

◆ AutoDiffScalar() [6/6]

template<typename DerivativeType >
Eigen::AutoDiffScalar< DerivativeType >::AutoDiffScalar ( const AutoDiffScalar< DerivativeType > &  other)
inline
148 : m_value(other.value()), m_derivatives(other.derivatives()) {}

Member Function Documentation

◆ derivatives() [1/2]

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

◆ derivatives() [2/2]

◆ operator!=() [1/2]

template<typename DerivativeType >
template<typename OtherDerType >
bool Eigen::AutoDiffScalar< DerivativeType >::operator!= ( const AutoDiffScalar< OtherDerType > &  b) const
inline
213  {
214  return m_value != b.value();
215  }
Scalar * b
Definition: benchVecAdd.cpp:17

References b, and Eigen::AutoDiffScalar< DerivativeType >::m_value.

◆ operator!=() [2/2]

template<typename DerivativeType >
bool Eigen::AutoDiffScalar< DerivativeType >::operator!= ( const Scalar other) const
inline
183 { return m_value != other; }

References Eigen::AutoDiffScalar< DerivativeType >::m_value.

◆ operator*() [1/2]

template<typename DerivativeType >
template<typename OtherDerType >
auto Eigen::AutoDiffScalar< DerivativeType >::operator* ( const AutoDiffScalar< OtherDerType > &  other) const
inline
342  {
343  return MakeAutoDiffScalar(m_value * other.value(),
344  internal::MakeCoherentCwiseBinaryOp<internal::scalar_sum_op<Scalar>>(
345  m_derivatives * other.value(), other.derivatives() * m_value));
346  }
auto MakeCoherentCwiseBinaryOp(const LhsDerivativeType &x, const RhsDerivativeType &y, Op op=Op())
Definition: AutoDiffScalar.h:52
AutoDiffScalar< NewDerType > MakeAutoDiffScalar(const typename NewDerType::Scalar &value, const NewDerType &der)
Definition: AutoDiffScalar.h:64

References Eigen::AutoDiffScalar< DerivativeType >::derivatives(), Eigen::AutoDiffScalar< DerivativeType >::m_derivatives, Eigen::AutoDiffScalar< DerivativeType >::m_value, Eigen::MakeAutoDiffScalar(), Eigen::internal::MakeCoherentCwiseBinaryOp(), and Eigen::AutoDiffScalar< DerivativeType >::value().

◆ operator*() [2/2]

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

◆ operator*=() [1/2]

template<typename DerivativeType >
template<typename OtherDerType >
AutoDiffScalar& Eigen::AutoDiffScalar< DerivativeType >::operator*= ( const AutoDiffScalar< OtherDerType > &  other)
inline
354  {
355  *this = *this * other;
356  return *this;
357  }

◆ operator*=() [2/2]

template<typename DerivativeType >
AutoDiffScalar& Eigen::AutoDiffScalar< DerivativeType >::operator*= ( const Scalar other)
inline
348  {
349  *this = *this * other;
350  return *this;
351  }

◆ operator+() [1/2]

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

◆ operator+() [2/2]

template<typename DerivativeType >
AutoDiffScalar<DerType&> Eigen::AutoDiffScalar< DerivativeType >::operator+ ( const Scalar other) const
inline
217  {
219  }
A scalar type replacement with automatic differentiation capability.
Definition: AutoDiffScalar.h:99

References Eigen::AutoDiffScalar< DerivativeType >::m_derivatives, and Eigen::AutoDiffScalar< DerivativeType >::m_value.

◆ operator+=() [1/2]

template<typename DerivativeType >
template<typename OtherDerType >
AutoDiffScalar& Eigen::AutoDiffScalar< DerivativeType >::operator+= ( const AutoDiffScalar< OtherDerType > &  other)
inline
248  {
249  (*this) = (*this) + other;
250  return *this;
251  }

◆ operator+=() [2/2]

template<typename DerivativeType >
AutoDiffScalar& Eigen::AutoDiffScalar< DerivativeType >::operator+= ( const Scalar other)
inline
235  {
236  value() += other;
237  return *this;
238  }

References Eigen::AutoDiffScalar< DerivativeType >::value().

◆ operator-() [1/3]

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

◆ operator-() [2/3]

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

◆ operator-() [3/3]

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

◆ operator-=() [1/2]

template<typename DerivativeType >
template<typename OtherDerType >
AutoDiffScalar& Eigen::AutoDiffScalar< DerivativeType >::operator-= ( const AutoDiffScalar< OtherDerType > &  other)
inline
276  {
277  *this = *this - other;
278  return *this;
279  }

◆ operator-=() [2/2]

template<typename DerivativeType >
AutoDiffScalar& Eigen::AutoDiffScalar< DerivativeType >::operator-= ( const Scalar other)
inline
263  {
264  value() -= other;
265  return *this;
266  }

References Eigen::AutoDiffScalar< DerivativeType >::value().

◆ operator/() [1/2]

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

◆ operator/() [2/2]

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

◆ operator/=() [1/2]

template<typename DerivativeType >
template<typename OtherDerType >
AutoDiffScalar& Eigen::AutoDiffScalar< DerivativeType >::operator/= ( const AutoDiffScalar< OtherDerType > &  other)
inline
365  {
366  *this = *this / other;
367  return *this;
368  }

◆ operator/=() [2/2]

template<typename DerivativeType >
AutoDiffScalar& Eigen::AutoDiffScalar< DerivativeType >::operator/= ( const Scalar other)
inline
359  {
360  *this = *this / other;
361  return *this;
362  }

◆ operator<() [1/2]

template<typename DerivativeType >
template<typename OtherDerType >
bool Eigen::AutoDiffScalar< DerivativeType >::operator< ( const AutoDiffScalar< OtherDerType > &  b) const
inline
193  {
194  return m_value < b.value();
195  }

References b, and Eigen::AutoDiffScalar< DerivativeType >::m_value.

◆ operator<() [2/2]

template<typename DerivativeType >
bool Eigen::AutoDiffScalar< DerivativeType >::operator< ( const Scalar other) const
inline
178 { return m_value < other; }

References Eigen::AutoDiffScalar< DerivativeType >::m_value.

◆ operator<=() [1/2]

template<typename DerivativeType >
template<typename OtherDerType >
bool Eigen::AutoDiffScalar< DerivativeType >::operator<= ( const AutoDiffScalar< OtherDerType > &  b) const
inline
197  {
198  return m_value <= b.value();
199  }

References b, and Eigen::AutoDiffScalar< DerivativeType >::m_value.

◆ operator<=() [2/2]

template<typename DerivativeType >
bool Eigen::AutoDiffScalar< DerivativeType >::operator<= ( const Scalar other) const
inline
179 { return m_value <= other; }

References Eigen::AutoDiffScalar< DerivativeType >::m_value.

◆ operator=() [1/3]

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

◆ operator=() [2/3]

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

◆ operator=() [3/3]

template<typename DerivativeType >
AutoDiffScalar& Eigen::AutoDiffScalar< DerivativeType >::operator= ( const Scalar other)
inline
163  {
164  m_value = other;
165  if (m_derivatives.size() > 0) m_derivatives.setZero();
166  return *this;
167  }

References Eigen::AutoDiffScalar< DerivativeType >::m_derivatives, and Eigen::AutoDiffScalar< DerivativeType >::m_value.

◆ operator==() [1/2]

template<typename DerivativeType >
template<typename OtherDerType >
bool Eigen::AutoDiffScalar< DerivativeType >::operator== ( const AutoDiffScalar< OtherDerType > &  b) const
inline
209  {
210  return m_value == b.value();
211  }

References b, and Eigen::AutoDiffScalar< DerivativeType >::m_value.

◆ operator==() [2/2]

template<typename DerivativeType >
bool Eigen::AutoDiffScalar< DerivativeType >::operator== ( const Scalar other) const
inline
182 { return m_value == other; }

References Eigen::AutoDiffScalar< DerivativeType >::m_value.

◆ operator>() [1/2]

template<typename DerivativeType >
template<typename OtherDerType >
bool Eigen::AutoDiffScalar< DerivativeType >::operator> ( const AutoDiffScalar< OtherDerType > &  b) const
inline
201  {
202  return m_value > b.value();
203  }

References b, and Eigen::AutoDiffScalar< DerivativeType >::m_value.

◆ operator>() [2/2]

template<typename DerivativeType >
bool Eigen::AutoDiffScalar< DerivativeType >::operator> ( const Scalar other) const
inline
180 { return m_value > other; }

References Eigen::AutoDiffScalar< DerivativeType >::m_value.

◆ operator>=() [1/2]

template<typename DerivativeType >
template<typename OtherDerType >
bool Eigen::AutoDiffScalar< DerivativeType >::operator>= ( const AutoDiffScalar< OtherDerType > &  b) const
inline
205  {
206  return m_value >= b.value();
207  }

References b, and Eigen::AutoDiffScalar< DerivativeType >::m_value.

◆ operator>=() [2/2]

template<typename DerivativeType >
bool Eigen::AutoDiffScalar< DerivativeType >::operator>= ( const Scalar other) const
inline
181 { return m_value >= other; }

References Eigen::AutoDiffScalar< DerivativeType >::m_value.

◆ value() [1/2]

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

◆ value() [2/2]

Friends And Related Function Documentation

◆ operator!=

template<typename DerivativeType >
bool operator!= ( const Scalar a,
const AutoDiffScalar< DerivativeType > &  b 
)
friend
190 { return a != b.value(); }
const Scalar * a
Definition: level2_cplx_impl.h:32

◆ operator*

template<typename DerivativeType >
auto operator* ( const Scalar other,
const AutoDiffScalar< DerivativeType > &  a 
)
friend
289  {
290  return MakeAutoDiffScalar(a.value() * other, a.derivatives() * other);
291  }

◆ operator+

template<typename DerivativeType >
AutoDiffScalar<DerType&> operator+ ( const Scalar a,
const AutoDiffScalar< DerivativeType > &  b 
)
friend
221  {
222  return AutoDiffScalar<DerType&>(a + b.value(), b.derivatives());
223  }

◆ operator-

template<typename DerivativeType >
AutoDiffScalar<CwiseUnaryOp<internal::scalar_opposite_op<Scalar>, const DerType> > operator- ( const Scalar a,
const AutoDiffScalar< DerivativeType > &  b 
)
friend
258  {
260  -b.derivatives());
261  }

◆ operator/

template<typename DerivativeType >
auto operator/ ( const Scalar other,
const AutoDiffScalar< DerivativeType > &  a 
)
friend
313  {
314  return MakeAutoDiffScalar(other / a.value(), a.derivatives() * (Scalar(-other) / (a.value() * a.value())));
315  }

◆ operator<

template<typename DerivativeType >
bool operator< ( const Scalar a,
const AutoDiffScalar< DerivativeType > &  b 
)
friend
185 { return a < b.value(); }

◆ operator<<

template<typename DerivativeType >
std::ostream& operator<< ( std::ostream &  s,
const AutoDiffScalar< DerivativeType > &  a 
)
friend
146 { return s << a.value(); }
RealScalar s
Definition: level1_cplx_impl.h:130

◆ operator<=

template<typename DerivativeType >
bool operator<= ( const Scalar a,
const AutoDiffScalar< DerivativeType > &  b 
)
friend
186 { return a <= b.value(); }

◆ operator==

template<typename DerivativeType >
bool operator== ( const Scalar a,
const AutoDiffScalar< DerivativeType > &  b 
)
friend
189 { return a == b.value(); }

◆ operator>

template<typename DerivativeType >
bool operator> ( const Scalar a,
const AutoDiffScalar< DerivativeType > &  b 
)
friend
187 { return a > b.value(); }

◆ operator>=

template<typename DerivativeType >
bool operator>= ( const Scalar a,
const AutoDiffScalar< DerivativeType > &  b 
)
friend
188 { return a >= b.value(); }

Member Data Documentation

◆ m_derivatives

◆ m_value


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