PolyFEM
|
Automatic differentiation scalar with first-order derivatives. More...
#include <autodiff.h>
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. | |
DScalar1 (size_t index, const Scalar &value_) | |
Construct a new scalar with the specified value and one first derivative set to 1. | |
DScalar1 (Scalar value_, const Gradient &grad_) | |
Construct a scalar associated with the given gradient. | |
DScalar1 (const DScalar1 &s) | |
Copy constructor. | |
const Scalar & | getValue () const |
const Gradient & | getGradient () 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. | |
static DVector3 | vector (const Eigen::Matrix< Scalar, 3, 1 > &v) |
Create a constant three-dimensional vector. | |
Static Public Member Functions inherited from DiffScalarBase | |
static void | setVariableCount (size_t value) |
Set the independent variable count used by the automatic differentiation layer. | |
static size_t | getVariableCount () |
Get the variable count used by the automatic differentiation layer. | |
Protected Attributes | |
Scalar | value |
Gradient | grad |
Friends | |
Miscellaneous functions | |
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 | |
DScalar1 & | operator+= (const DScalar1 &s) |
DScalar1 & | operator+= (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 | |
DScalar1 & | operator-= (const DScalar1 &s) |
DScalar1 & | operator-= (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 | |
DScalar1 & | operator/= (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 | |
DScalar1 & | operator*= (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 |
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)
Definition at line 111 of file autodiff.h.
typedef Eigen::Matrix<DScalar1, 2, 1> DScalar1< _Scalar, _Gradient >::DVector2 |
Definition at line 116 of file autodiff.h.
typedef Eigen::Matrix<DScalar1, 3, 1> DScalar1< _Scalar, _Gradient >::DVector3 |
Definition at line 117 of file autodiff.h.
typedef _Gradient DScalar1< _Scalar, _Gradient >::Gradient |
Definition at line 115 of file autodiff.h.
typedef _Scalar DScalar1< _Scalar, _Gradient >::Scalar |
Definition at line 114 of file autodiff.h.
|
inlineexplicit |
Create a new constant automatic differentiation scalar.
Definition at line 124 of file autodiff.h.
References DiffScalarBase::getVariableCount(), and DScalar1< _Scalar, _Gradient >::grad.
|
inline |
Construct a new scalar with the specified value and one first derivative set to 1.
Definition at line 132 of file autodiff.h.
References DiffScalarBase::getVariableCount(), and DScalar1< _Scalar, _Gradient >::grad.
|
inline |
Construct a scalar associated with the given gradient.
Definition at line 142 of file autodiff.h.
|
inline |
Copy constructor.
Definition at line 146 of file autodiff.h.
|
inline |
Definition at line 150 of file autodiff.h.
References DScalar1< _Scalar, _Gradient >::grad.
Referenced by operator<<().
|
inline |
Definition at line 149 of file autodiff.h.
References DScalar1< _Scalar, _Gradient >::value.
Referenced by operator<<().
|
inline |
Definition at line 404 of file autodiff.h.
References DScalar1< _Scalar, _Gradient >::value.
|
inline |
Definition at line 285 of file autodiff.h.
References DScalar1< _Scalar, _Gradient >::grad, and DScalar1< _Scalar, _Gradient >::value.
|
inline |
Definition at line 170 of file autodiff.h.
References DScalar1< _Scalar, _Gradient >::grad, and DScalar1< _Scalar, _Gradient >::value.
|
inline |
Definition at line 177 of file autodiff.h.
References DScalar1< _Scalar, _Gradient >::value.
|
inline |
Definition at line 210 of file autodiff.h.
References DScalar1< _Scalar, _Gradient >::grad, and DScalar1< _Scalar, _Gradient >::value.
|
inline |
Definition at line 217 of file autodiff.h.
References DScalar1< _Scalar, _Gradient >::value.
|
inline |
Definition at line 255 of file autodiff.h.
References DScalar1< _Scalar, _Gradient >::grad, and DScalar1< _Scalar, _Gradient >::value.
|
inline |
Definition at line 395 of file autodiff.h.
References DScalar1< _Scalar, _Gradient >::value.
|
inline |
Definition at line 399 of file autodiff.h.
References DScalar1< _Scalar, _Gradient >::value.
|
inline |
Definition at line 396 of file autodiff.h.
References DScalar1< _Scalar, _Gradient >::value.
|
inline |
Definition at line 400 of file autodiff.h.
References DScalar1< _Scalar, _Gradient >::value.
|
inline |
Definition at line 385 of file autodiff.h.
References DScalar1< _Scalar, _Gradient >::grad, and DScalar1< _Scalar, _Gradient >::value.
|
inline |
Definition at line 390 of file autodiff.h.
References DScalar1< _Scalar, _Gradient >::grad, and DScalar1< _Scalar, _Gradient >::value.
|
inline |
Definition at line 403 of file autodiff.h.
References DScalar1< _Scalar, _Gradient >::value.
|
inline |
Definition at line 397 of file autodiff.h.
References DScalar1< _Scalar, _Gradient >::value.
|
inline |
Definition at line 401 of file autodiff.h.
References DScalar1< _Scalar, _Gradient >::value.
|
inline |
Definition at line 398 of file autodiff.h.
References DScalar1< _Scalar, _Gradient >::value.
|
inline |
Definition at line 402 of file autodiff.h.
References DScalar1< _Scalar, _Gradient >::value.
|
inlinestatic |
Initialize a constant two-dimensional vector.
Definition at line 414 of file autodiff.h.
|
inlinestatic |
Create a constant three-dimensional vector.
Definition at line 420 of file autodiff.h.
|
friend |
Definition at line 345 of file autodiff.h.
|
friend |
Definition at line 357 of file autodiff.h.
|
friend |
Definition at line 369 of file autodiff.h.
|
friend |
Definition at line 339 of file autodiff.h.
|
friend |
Definition at line 317 of file autodiff.h.
|
friend |
Definition at line 246 of file autodiff.h.
|
friend |
Definition at line 325 of file autodiff.h.
|
friend |
Definition at line 278 of file autodiff.h.
|
friend |
Definition at line 268 of file autodiff.h.
|
friend |
Definition at line 273 of file autodiff.h.
|
friend |
Definition at line 155 of file autodiff.h.
|
friend |
Definition at line 160 of file autodiff.h.
|
friend |
Definition at line 165 of file autodiff.h.
|
friend |
Definition at line 190 of file autodiff.h.
|
friend |
Definition at line 195 of file autodiff.h.
|
friend |
Definition at line 205 of file autodiff.h.
|
friend |
Definition at line 200 of file autodiff.h.
|
friend |
Definition at line 241 of file autodiff.h.
|
friend |
Definition at line 228 of file autodiff.h.
|
friend |
Definition at line 236 of file autodiff.h.
|
friend |
Definition at line 309 of file autodiff.h.
|
friend |
Definition at line 333 of file autodiff.h.
|
friend |
Definition at line 299 of file autodiff.h.
|
protected |
Definition at line 455 of file autodiff.h.
Referenced by DScalar1< _Scalar, _Gradient >::DScalar1(), DScalar1< _Scalar, _Gradient >::DScalar1(), DScalar1< _Scalar, _Gradient >::getGradient(), DScalar1< _Scalar, _Gradient >::operator*=(), DScalar1< _Scalar, _Gradient >::operator+=(), DScalar1< _Scalar, _Gradient >::operator-=(), DScalar1< _Scalar, _Gradient >::operator/=(), DScalar1< _Scalar, _Gradient >::operator=(), and DScalar1< _Scalar, _Gradient >::operator=().
|
protected |
Definition at line 454 of file autodiff.h.
Referenced by DScalar1< _Scalar, _Gradient >::getValue(), DScalar1< _Scalar, _Gradient >::operator!=(), DScalar1< _Scalar, _Gradient >::operator*=(), DScalar1< _Scalar, _Gradient >::operator+=(), DScalar1< _Scalar, _Gradient >::operator+=(), DScalar1< _Scalar, _Gradient >::operator-=(), DScalar1< _Scalar, _Gradient >::operator-=(), DScalar1< _Scalar, _Gradient >::operator/=(), DScalar1< _Scalar, _Gradient >::operator<(), DScalar1< _Scalar, _Gradient >::operator<(), DScalar1< _Scalar, _Gradient >::operator<=(), DScalar1< _Scalar, _Gradient >::operator<=(), DScalar1< _Scalar, _Gradient >::operator=(), DScalar1< _Scalar, _Gradient >::operator=(), DScalar1< _Scalar, _Gradient >::operator==(), DScalar1< _Scalar, _Gradient >::operator>(), DScalar1< _Scalar, _Gradient >::operator>(), DScalar1< _Scalar, _Gradient >::operator>=(), and DScalar1< _Scalar, _Gradient >::operator>=().