Wildmeshing Toolkit
DScalar1< _Scalar, _Gradient > Struct Template Reference

Automatic differentiation scalar with first-order derivatives. More...

#include <autodiff.h>

Inheritance diagram for DScalar1< _Scalar, _Gradient >:
[legend]
Collaboration diagram for DScalar1< _Scalar, _Gradient >:
[legend]

Public Types

typedef _Scalar Scalar
 
typedef _Gradient Gradient
 
typedef Eigen::Matrix< DScalar1, 2, 1 > DVector2
 
typedef Eigen::Matrix< DScalar1, 3, 1 > DVector3
 

Public Member Functions

Constructors and accessors
 DScalar1 (Scalar value_=(Scalar) 0)
 Create a new constant automatic differentiation scalar. More...
 
 DScalar1 (size_t index, const Scalar &value_)
 Construct a new scalar with the specified value and one first derivative set to 1. More...
 
 DScalar1 (Scalar value_, const Gradient &grad_)
 Construct a scalar associated with the given gradient. More...
 
 DScalar1 (const DScalar1 &s)
 Copy constructor. More...
 
const ScalargetValue () const
 
const GradientgetGradient () const
 
Comparison and assignment
void operator= (const DScalar1 &s)
 
void operator= (const Scalar &v)
 
bool operator< (const DScalar1 &s) const
 
bool operator<= (const DScalar1 &s) const
 
bool operator> (const DScalar1 &s) const
 
bool operator>= (const DScalar1 &s) const
 
bool operator< (const Scalar &s) const
 
bool operator<= (const Scalar &s) const
 
bool operator> (const Scalar &s) const
 
bool operator>= (const Scalar &s) const
 
bool operator== (const Scalar &s) const
 
bool operator!= (const Scalar &s) const
 

Static Public Member Functions

Vector helper functions
static DVector2 vector (const Eigen::Matrix< Scalar, 2, 1 > &v)
 Initialize a constant two-dimensional vector. More...
 
static DVector3 vector (const Eigen::Matrix< Scalar, 3, 1 > &v)
 Create a constant three-dimensional vector. More...
 
- Static Public Member Functions inherited from DiffScalarBase
static void setVariableCount (size_t value)
 Set the independent variable count used by the automatic differentiation layer. More...
 
static size_t getVariableCount ()
 Get the variable count used by the automatic differentiation layer. More...
 

Protected Attributes

Scalar value
 
Gradient grad
 

Friends

Miscellaneous functions
DScalar1 abs (const DScalar1 &s)
 
DScalar1 sqrt (const DScalar1 &s)
 
DScalar1 pow (const DScalar1 &s, const Scalar &a)
 
DScalar1 exp (const DScalar1 &s)
 
DScalar1 log (const DScalar1 &s)
 
DScalar1 sin (const DScalar1 &s)
 
DScalar1 cos (const DScalar1 &s)
 
DScalar1 acos (const DScalar1 &s)
 
DScalar1 asin (const DScalar1 &s)
 
DScalar1 atan2 (const DScalar1 &y, const DScalar1 &x)
 

Addition

DScalar1operator+= (const DScalar1 &s)
 
DScalar1operator+= (const Scalar &v)
 
DScalar1 operator+ (const DScalar1 &lhs, const DScalar1 &rhs)
 
DScalar1 operator+ (const DScalar1 &lhs, const Scalar &rhs)
 
DScalar1 operator+ (const Scalar &lhs, const DScalar1 &rhs)
 

Subtraction

DScalar1operator-= (const DScalar1 &s)
 
DScalar1operator-= (const Scalar &v)
 
DScalar1 operator- (const DScalar1 &lhs, const DScalar1 &rhs)
 
DScalar1 operator- (const DScalar1 &lhs, const Scalar &rhs)
 
DScalar1 operator- (const Scalar &lhs, const DScalar1 &rhs)
 
DScalar1 operator- (const DScalar1 &s)
 

Division

DScalar1operator/= (const Scalar &v)
 
DScalar1 operator/ (const DScalar1 &lhs, const Scalar &rhs)
 
DScalar1 operator/ (const Scalar &lhs, const DScalar1 &rhs)
 
DScalar1 operator/ (const DScalar1 &lhs, const DScalar1 &rhs)
 
DScalar1 inverse (const DScalar1 &s)
 

Multiplication

DScalar1operator*= (const Scalar &v)
 
DScalar1 operator* (const DScalar1 &lhs, const Scalar &rhs)
 
DScalar1 operator* (const Scalar &lhs, const DScalar1 &rhs)
 
DScalar1 operator* (const DScalar1 &lhs, const DScalar1 &rhs)
 

Additional Inherited Members

- Static Public Attributes inherited from DiffScalarBase
static thread_local size_t m_variableCount
 

Detailed Description

template<typename _Scalar, typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
struct DScalar1< _Scalar, _Gradient >

Automatic differentiation scalar with first-order derivatives.

This class provides an instrumented "scalar" value, which may be dependent on a number of independent variables. The implementation keeps tracks of first -order drivatives with respect to these variables using a set of overloaded operations and implementations of special functions (sin, tan, exp, ..).

This is extremely useful for numerical zero-finding, particularly when analytic derivatives from programs like Maple or Mathematica suffer from excessively complicated expressions.

The class relies on templates, which makes it possible to fix the number of independent variables at compile-time so that instances can be allocated on the stack. Otherwise, they will be placed on the heap.

This is an extended C++ port of Jon Kaldor's implementation, which is based on a C version by Eitan Grinspun at Caltech)

See also
DScalar2
Author
Wenzel Jakob

Definition at line 114 of file autodiff.h.

Member Typedef Documentation

◆ DVector2

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
typedef Eigen::Matrix<DScalar1, 2, 1> DScalar1< _Scalar, _Gradient >::DVector2

Definition at line 119 of file autodiff.h.

◆ DVector3

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
typedef Eigen::Matrix<DScalar1, 3, 1> DScalar1< _Scalar, _Gradient >::DVector3

Definition at line 120 of file autodiff.h.

◆ Gradient

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
typedef _Gradient DScalar1< _Scalar, _Gradient >::Gradient

Definition at line 118 of file autodiff.h.

◆ Scalar

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
typedef _Scalar DScalar1< _Scalar, _Gradient >::Scalar

Definition at line 117 of file autodiff.h.

Constructor & Destructor Documentation

◆ DScalar1() [1/4]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1< _Scalar, _Gradient >::DScalar1 ( Scalar  value_ = (Scalar)0)
inlineexplicit

Create a new constant automatic differentiation scalar.

Definition at line 127 of file autodiff.h.

References DiffScalarBase::getVariableCount(), and DScalar1< _Scalar, _Gradient >::grad.

Referenced by DScalar1< _Scalar, _Gradient >::vector().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DScalar1() [2/4]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1< _Scalar, _Gradient >::DScalar1 ( size_t  index,
const Scalar value_ 
)
inline

Construct a new scalar with the specified value and one first derivative set to 1.

Definition at line 135 of file autodiff.h.

References DiffScalarBase::getVariableCount(), and DScalar1< _Scalar, _Gradient >::grad.

Here is the call graph for this function:

◆ DScalar1() [3/4]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1< _Scalar, _Gradient >::DScalar1 ( Scalar  value_,
const Gradient grad_ 
)
inline

Construct a scalar associated with the given gradient.

Definition at line 145 of file autodiff.h.

◆ DScalar1() [4/4]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1< _Scalar, _Gradient >::DScalar1 ( const DScalar1< _Scalar, _Gradient > &  s)
inline

Copy constructor.

Definition at line 149 of file autodiff.h.

Member Function Documentation

◆ getGradient()

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
const Gradient& DScalar1< _Scalar, _Gradient >::getGradient ( ) const
inline

Definition at line 153 of file autodiff.h.

References DScalar1< _Scalar, _Gradient >::grad.

Referenced by operator<<().

Here is the caller graph for this function:

◆ getValue()

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
const Scalar& DScalar1< _Scalar, _Gradient >::getValue ( ) const
inline

Definition at line 152 of file autodiff.h.

References DScalar1< _Scalar, _Gradient >::value.

Referenced by operator<<().

Here is the caller graph for this function:

◆ operator!=()

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
bool DScalar1< _Scalar, _Gradient >::operator!= ( const Scalar s) const
inline

Definition at line 412 of file autodiff.h.

References DScalar1< _Scalar, _Gradient >::value.

◆ operator*=()

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1& DScalar1< _Scalar, _Gradient >::operator*= ( const Scalar v)
inline

◆ operator+=() [1/2]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1& DScalar1< _Scalar, _Gradient >::operator+= ( const DScalar1< _Scalar, _Gradient > &  s)
inline

◆ operator+=() [2/2]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1& DScalar1< _Scalar, _Gradient >::operator+= ( const Scalar v)
inline

Definition at line 180 of file autodiff.h.

References DScalar1< _Scalar, _Gradient >::value.

◆ operator-=() [1/2]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1& DScalar1< _Scalar, _Gradient >::operator-= ( const DScalar1< _Scalar, _Gradient > &  s)
inline

◆ operator-=() [2/2]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1& DScalar1< _Scalar, _Gradient >::operator-= ( const Scalar v)
inline

Definition at line 220 of file autodiff.h.

References DScalar1< _Scalar, _Gradient >::value.

◆ operator/=()

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1& DScalar1< _Scalar, _Gradient >::operator/= ( const Scalar v)
inline

◆ operator<() [1/2]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
bool DScalar1< _Scalar, _Gradient >::operator< ( const DScalar1< _Scalar, _Gradient > &  s) const
inline

Definition at line 403 of file autodiff.h.

References DScalar1< _Scalar, _Gradient >::value.

◆ operator<() [2/2]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
bool DScalar1< _Scalar, _Gradient >::operator< ( const Scalar s) const
inline

Definition at line 407 of file autodiff.h.

References DScalar1< _Scalar, _Gradient >::value.

◆ operator<=() [1/2]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
bool DScalar1< _Scalar, _Gradient >::operator<= ( const DScalar1< _Scalar, _Gradient > &  s) const
inline

Definition at line 404 of file autodiff.h.

References DScalar1< _Scalar, _Gradient >::value.

◆ operator<=() [2/2]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
bool DScalar1< _Scalar, _Gradient >::operator<= ( const Scalar s) const
inline

Definition at line 408 of file autodiff.h.

References DScalar1< _Scalar, _Gradient >::value.

◆ operator=() [1/2]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
void DScalar1< _Scalar, _Gradient >::operator= ( const DScalar1< _Scalar, _Gradient > &  s)
inline

◆ operator=() [2/2]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
void DScalar1< _Scalar, _Gradient >::operator= ( const Scalar v)
inline

◆ operator==()

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
bool DScalar1< _Scalar, _Gradient >::operator== ( const Scalar s) const
inline

Definition at line 411 of file autodiff.h.

References DScalar1< _Scalar, _Gradient >::value.

◆ operator>() [1/2]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
bool DScalar1< _Scalar, _Gradient >::operator> ( const DScalar1< _Scalar, _Gradient > &  s) const
inline

Definition at line 405 of file autodiff.h.

References DScalar1< _Scalar, _Gradient >::value.

◆ operator>() [2/2]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
bool DScalar1< _Scalar, _Gradient >::operator> ( const Scalar s) const
inline

Definition at line 409 of file autodiff.h.

References DScalar1< _Scalar, _Gradient >::value.

◆ operator>=() [1/2]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
bool DScalar1< _Scalar, _Gradient >::operator>= ( const DScalar1< _Scalar, _Gradient > &  s) const
inline

Definition at line 406 of file autodiff.h.

References DScalar1< _Scalar, _Gradient >::value.

◆ operator>=() [2/2]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
bool DScalar1< _Scalar, _Gradient >::operator>= ( const Scalar s) const
inline

Definition at line 410 of file autodiff.h.

References DScalar1< _Scalar, _Gradient >::value.

◆ vector() [1/2]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
static DVector2 DScalar1< _Scalar, _Gradient >::vector ( const Eigen::Matrix< Scalar, 2, 1 > &  v)
inlinestatic

Initialize a constant two-dimensional vector.

Definition at line 422 of file autodiff.h.

References DScalar1< _Scalar, _Gradient >::DScalar1().

Here is the call graph for this function:

◆ vector() [2/2]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
static DVector3 DScalar1< _Scalar, _Gradient >::vector ( const Eigen::Matrix< Scalar, 3, 1 > &  v)
inlinestatic

Create a constant three-dimensional vector.

Definition at line 428 of file autodiff.h.

References DScalar1< _Scalar, _Gradient >::DScalar1().

Here is the call graph for this function:

Friends And Related Function Documentation

◆ abs

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1 abs ( const DScalar1< _Scalar, _Gradient > &  s)
friend

Definition at line 302 of file autodiff.h.

◆ acos

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1 acos ( const DScalar1< _Scalar, _Gradient > &  s)
friend

Definition at line 353 of file autodiff.h.

◆ asin

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1 asin ( const DScalar1< _Scalar, _Gradient > &  s)
friend

Definition at line 365 of file autodiff.h.

◆ atan2

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1 atan2 ( const DScalar1< _Scalar, _Gradient > &  y,
const DScalar1< _Scalar, _Gradient > &  x 
)
friend

Definition at line 377 of file autodiff.h.

◆ cos

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1 cos ( const DScalar1< _Scalar, _Gradient > &  s)
friend

Definition at line 347 of file autodiff.h.

◆ exp

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1 exp ( const DScalar1< _Scalar, _Gradient > &  s)
friend

Definition at line 325 of file autodiff.h.

◆ inverse

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1 inverse ( const DScalar1< _Scalar, _Gradient > &  s)
friend

Definition at line 249 of file autodiff.h.

◆ log

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1 log ( const DScalar1< _Scalar, _Gradient > &  s)
friend

Definition at line 333 of file autodiff.h.

◆ operator* [1/3]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1 operator* ( const DScalar1< _Scalar, _Gradient > &  lhs,
const DScalar1< _Scalar, _Gradient > &  rhs 
)
friend

Definition at line 281 of file autodiff.h.

◆ operator* [2/3]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1 operator* ( const DScalar1< _Scalar, _Gradient > &  lhs,
const Scalar rhs 
)
friend

Definition at line 271 of file autodiff.h.

◆ operator* [3/3]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1 operator* ( const Scalar lhs,
const DScalar1< _Scalar, _Gradient > &  rhs 
)
friend

Definition at line 276 of file autodiff.h.

◆ operator+ [1/3]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1 operator+ ( const DScalar1< _Scalar, _Gradient > &  lhs,
const DScalar1< _Scalar, _Gradient > &  rhs 
)
friend

Definition at line 158 of file autodiff.h.

◆ operator+ [2/3]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1 operator+ ( const DScalar1< _Scalar, _Gradient > &  lhs,
const Scalar rhs 
)
friend

Definition at line 163 of file autodiff.h.

◆ operator+ [3/3]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1 operator+ ( const Scalar lhs,
const DScalar1< _Scalar, _Gradient > &  rhs 
)
friend

Definition at line 168 of file autodiff.h.

◆ operator- [1/4]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1 operator- ( const DScalar1< _Scalar, _Gradient > &  lhs,
const DScalar1< _Scalar, _Gradient > &  rhs 
)
friend

Definition at line 193 of file autodiff.h.

◆ operator- [2/4]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1 operator- ( const DScalar1< _Scalar, _Gradient > &  lhs,
const Scalar rhs 
)
friend

Definition at line 198 of file autodiff.h.

◆ operator- [3/4]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1 operator- ( const DScalar1< _Scalar, _Gradient > &  s)
friend

Definition at line 208 of file autodiff.h.

◆ operator- [4/4]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1 operator- ( const Scalar lhs,
const DScalar1< _Scalar, _Gradient > &  rhs 
)
friend

Definition at line 203 of file autodiff.h.

◆ operator/ [1/3]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1 operator/ ( const DScalar1< _Scalar, _Gradient > &  lhs,
const DScalar1< _Scalar, _Gradient > &  rhs 
)
friend

Definition at line 244 of file autodiff.h.

◆ operator/ [2/3]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1 operator/ ( const DScalar1< _Scalar, _Gradient > &  lhs,
const Scalar rhs 
)
friend

Definition at line 231 of file autodiff.h.

◆ operator/ [3/3]

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1 operator/ ( const Scalar lhs,
const DScalar1< _Scalar, _Gradient > &  rhs 
)
friend

Definition at line 239 of file autodiff.h.

◆ pow

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1 pow ( const DScalar1< _Scalar, _Gradient > &  s,
const Scalar a 
)
friend

Definition at line 317 of file autodiff.h.

◆ sin

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1 sin ( const DScalar1< _Scalar, _Gradient > &  s)
friend

Definition at line 341 of file autodiff.h.

◆ sqrt

template<typename _Scalar , typename _Gradient = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>>
DScalar1 sqrt ( const DScalar1< _Scalar, _Gradient > &  s)
friend

Definition at line 307 of file autodiff.h.

Member Data Documentation

◆ grad

◆ value


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