PolyFEM
|
Automatic differentiation scalar with first- and second-order derivatives. More...
#include <autodiff.h>
Public Types | |
typedef _Scalar | Scalar |
typedef _Gradient | Gradient |
typedef _Hessian | Hessian |
typedef Eigen::Matrix< DScalar2, 2, 1 > | DVector2 |
typedef Eigen::Matrix< DScalar2, 3, 1 > | DVector3 |
Public Member Functions | |
Constructors and accessors | |
DScalar2 (Scalar value_=(Scalar) 0) | |
Create a new constant automatic differentiation scalar. | |
DScalar2 (size_t index, const Scalar &value_) | |
Construct a new scalar with the specified value and one first derivative set to 1. | |
DScalar2 (Scalar value_, const Gradient &grad_, const Hessian &hess_) | |
Construct a scalar associated with the given gradient and Hessian. | |
DScalar2 (const DScalar2 &s) | |
Copy constructor. | |
const Scalar & | getValue () const |
const Gradient & | getGradient () const |
const Hessian & | getHessian () const |
Comparison and assignment | |
void | operator= (const DScalar2 &s) |
void | operator= (const Scalar &v) |
bool | operator< (const DScalar2 &s) const |
bool | operator<= (const DScalar2 &s) const |
bool | operator> (const DScalar2 &s) const |
bool | operator>= (const DScalar2 &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 |
Hessian | hess |
Friends | |
Miscellaneous functions | |
DScalar2 | sqrt (const DScalar2 &s) |
DScalar2 | pow (const DScalar2 &s, const Scalar &a) |
DScalar2 | exp (const DScalar2 &s) |
DScalar2 | log (const DScalar2 &s) |
DScalar2 | sin (const DScalar2 &s) |
DScalar2 | cos (const DScalar2 &s) |
DScalar2 | acos (const DScalar2 &s) |
DScalar2 | asin (const DScalar2 &s) |
DScalar2 | atan2 (const DScalar2 &y, const DScalar2 &x) |
Addition | |
DScalar2 & | operator+= (const DScalar2 &s) |
DScalar2 & | operator+= (const Scalar &v) |
DScalar2 | operator+ (const DScalar2 &lhs, const DScalar2 &rhs) |
DScalar2 | operator+ (const DScalar2 &lhs, const Scalar &rhs) |
DScalar2 | operator+ (const Scalar &lhs, const DScalar2 &rhs) |
Subtraction | |
DScalar2 & | operator-= (const DScalar2 &s) |
DScalar2 & | operator-= (const Scalar &v) |
DScalar2 | operator- (const DScalar2 &lhs, const DScalar2 &rhs) |
DScalar2 | operator- (const DScalar2 &lhs, const Scalar &rhs) |
DScalar2 | operator- (const Scalar &lhs, const DScalar2 &rhs) |
DScalar2 | operator- (const DScalar2 &s) |
Division | |
DScalar2 & | operator/= (const Scalar &v) |
DScalar2 | operator/ (const DScalar2 &lhs, const Scalar &rhs) |
DScalar2 | operator/ (const Scalar &lhs, const DScalar2 &rhs) |
DScalar2 | operator/ (const DScalar2 &lhs, const DScalar2 &rhs) |
DScalar2 | inverse (const DScalar2 &s) |
Multiplication | |
DScalar2 & | operator*= (const Scalar &v) |
DScalar2 | operator* (const DScalar2 &lhs, const Scalar &rhs) |
DScalar2 | operator* (const Scalar &lhs, const DScalar2 &rhs) |
DScalar2 | operator* (const DScalar2 &lhs, const DScalar2 &rhs) |
Additional Inherited Members | |
Static Public Attributes inherited from DiffScalarBase | |
static thread_local size_t | m_variableCount |
Automatic differentiation scalar with first- and second-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 and second-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 optimization, 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 492 of file autodiff.h.
typedef Eigen::Matrix<DScalar2, 2, 1> DScalar2< _Scalar, _Gradient, _Hessian >::DVector2 |
Definition at line 498 of file autodiff.h.
typedef Eigen::Matrix<DScalar2, 3, 1> DScalar2< _Scalar, _Gradient, _Hessian >::DVector3 |
Definition at line 499 of file autodiff.h.
typedef _Gradient DScalar2< _Scalar, _Gradient, _Hessian >::Gradient |
Definition at line 496 of file autodiff.h.
typedef _Hessian DScalar2< _Scalar, _Gradient, _Hessian >::Hessian |
Definition at line 497 of file autodiff.h.
typedef _Scalar DScalar2< _Scalar, _Gradient, _Hessian >::Scalar |
Definition at line 495 of file autodiff.h.
|
inlineexplicit |
Create a new constant automatic differentiation scalar.
Definition at line 506 of file autodiff.h.
References DiffScalarBase::getVariableCount(), DScalar2< _Scalar, _Gradient, _Hessian >::grad, and DScalar2< _Scalar, _Gradient, _Hessian >::hess.
|
inline |
Construct a new scalar with the specified value and one first derivative set to 1.
Definition at line 517 of file autodiff.h.
References DiffScalarBase::getVariableCount(), DScalar2< _Scalar, _Gradient, _Hessian >::grad, and DScalar2< _Scalar, _Gradient, _Hessian >::hess.
|
inline |
Construct a scalar associated with the given gradient and Hessian.
Definition at line 530 of file autodiff.h.
|
inline |
Copy constructor.
Definition at line 534 of file autodiff.h.
|
inline |
Definition at line 538 of file autodiff.h.
References DScalar2< _Scalar, _Gradient, _Hessian >::grad.
Referenced by operator<<().
|
inline |
Definition at line 539 of file autodiff.h.
References DScalar2< _Scalar, _Gradient, _Hessian >::hess.
Referenced by operator<<().
|
inline |
Definition at line 537 of file autodiff.h.
References DScalar2< _Scalar, _Gradient, _Hessian >::value.
Referenced by operator<<().
|
inline |
Definition at line 913 of file autodiff.h.
References DScalar2< _Scalar, _Gradient, _Hessian >::value.
|
inline |
Definition at line 697 of file autodiff.h.
References DScalar2< _Scalar, _Gradient, _Hessian >::grad, DScalar2< _Scalar, _Gradient, _Hessian >::hess, and DScalar2< _Scalar, _Gradient, _Hessian >::value.
|
inline |
Definition at line 560 of file autodiff.h.
References DScalar2< _Scalar, _Gradient, _Hessian >::grad, DScalar2< _Scalar, _Gradient, _Hessian >::hess, and DScalar2< _Scalar, _Gradient, _Hessian >::value.
|
inline |
Definition at line 568 of file autodiff.h.
References DScalar2< _Scalar, _Gradient, _Hessian >::value.
|
inline |
Definition at line 601 of file autodiff.h.
References DScalar2< _Scalar, _Gradient, _Hessian >::grad, DScalar2< _Scalar, _Gradient, _Hessian >::hess, and DScalar2< _Scalar, _Gradient, _Hessian >::value.
|
inline |
Definition at line 609 of file autodiff.h.
References DScalar2< _Scalar, _Gradient, _Hessian >::value.
|
inline |
Definition at line 658 of file autodiff.h.
References DScalar2< _Scalar, _Gradient, _Hessian >::grad, DScalar2< _Scalar, _Gradient, _Hessian >::hess, and DScalar2< _Scalar, _Gradient, _Hessian >::value.
|
inline |
Definition at line 904 of file autodiff.h.
References DScalar2< _Scalar, _Gradient, _Hessian >::value.
|
inline |
Definition at line 908 of file autodiff.h.
References DScalar2< _Scalar, _Gradient, _Hessian >::value.
|
inline |
Definition at line 905 of file autodiff.h.
References DScalar2< _Scalar, _Gradient, _Hessian >::value.
|
inline |
Definition at line 909 of file autodiff.h.
References DScalar2< _Scalar, _Gradient, _Hessian >::value.
|
inline |
Definition at line 892 of file autodiff.h.
References DScalar2< _Scalar, _Gradient, _Hessian >::grad, DScalar2< _Scalar, _Gradient, _Hessian >::hess, and DScalar2< _Scalar, _Gradient, _Hessian >::value.
|
inline |
Definition at line 898 of file autodiff.h.
References DScalar2< _Scalar, _Gradient, _Hessian >::grad, DScalar2< _Scalar, _Gradient, _Hessian >::hess, and DScalar2< _Scalar, _Gradient, _Hessian >::value.
|
inline |
Definition at line 912 of file autodiff.h.
References DScalar2< _Scalar, _Gradient, _Hessian >::value.
|
inline |
Definition at line 906 of file autodiff.h.
References DScalar2< _Scalar, _Gradient, _Hessian >::value.
|
inline |
Definition at line 910 of file autodiff.h.
References DScalar2< _Scalar, _Gradient, _Hessian >::value.
|
inline |
Definition at line 907 of file autodiff.h.
References DScalar2< _Scalar, _Gradient, _Hessian >::value.
|
inline |
Definition at line 911 of file autodiff.h.
References DScalar2< _Scalar, _Gradient, _Hessian >::value.
|
inlinestatic |
Initialize a constant two-dimensional vector.
Definition at line 949 of file autodiff.h.
|
inlinestatic |
Create a constant three-dimensional vector.
Definition at line 955 of file autodiff.h.
|
friend |
Definition at line 818 of file autodiff.h.
|
friend |
Definition at line 839 of file autodiff.h.
|
friend |
Definition at line 860 of file autodiff.h.
|
friend |
Definition at line 801 of file autodiff.h.
|
friend |
Definition at line 749 of file autodiff.h.
|
friend |
Definition at line 638 of file autodiff.h.
|
friend |
Definition at line 767 of file autodiff.h.
|
friend |
Product rule
Definition at line 681 of file autodiff.h.
|
friend |
Definition at line 671 of file autodiff.h.
|
friend |
Definition at line 676 of file autodiff.h.
|
friend |
Definition at line 544 of file autodiff.h.
|
friend |
Definition at line 550 of file autodiff.h.
|
friend |
Definition at line 555 of file autodiff.h.
|
friend |
Definition at line 581 of file autodiff.h.
|
friend |
Definition at line 586 of file autodiff.h.
|
friend |
Definition at line 596 of file autodiff.h.
|
friend |
Definition at line 591 of file autodiff.h.
|
friend |
Definition at line 633 of file autodiff.h.
|
friend |
Definition at line 620 of file autodiff.h.
|
friend |
Definition at line 628 of file autodiff.h.
|
friend |
Definition at line 731 of file autodiff.h.
|
friend |
Definition at line 783 of file autodiff.h.
|
friend |
Definition at line 712 of file autodiff.h.
|
protected |
Definition at line 964 of file autodiff.h.
Referenced by DScalar2< _Scalar, _Gradient, _Hessian >::DScalar2(), DScalar2< _Scalar, _Gradient, _Hessian >::DScalar2(), DScalar2< _Scalar, _Gradient, _Hessian >::getGradient(), DScalar2< _Scalar, _Gradient, _Hessian >::operator*=(), DScalar2< _Scalar, _Gradient, _Hessian >::operator+=(), DScalar2< _Scalar, _Gradient, _Hessian >::operator-=(), DScalar2< _Scalar, _Gradient, _Hessian >::operator/=(), DScalar2< _Scalar, _Gradient, _Hessian >::operator=(), and DScalar2< _Scalar, _Gradient, _Hessian >::operator=().
|
protected |
Definition at line 965 of file autodiff.h.
Referenced by DScalar2< _Scalar, _Gradient, _Hessian >::DScalar2(), DScalar2< _Scalar, _Gradient, _Hessian >::DScalar2(), DScalar2< _Scalar, _Gradient, _Hessian >::getHessian(), DScalar2< _Scalar, _Gradient, _Hessian >::operator*=(), DScalar2< _Scalar, _Gradient, _Hessian >::operator+=(), DScalar2< _Scalar, _Gradient, _Hessian >::operator-=(), DScalar2< _Scalar, _Gradient, _Hessian >::operator/=(), DScalar2< _Scalar, _Gradient, _Hessian >::operator=(), and DScalar2< _Scalar, _Gradient, _Hessian >::operator=().
|
protected |
Definition at line 963 of file autodiff.h.
Referenced by DScalar2< _Scalar, _Gradient, _Hessian >::getValue(), DScalar2< _Scalar, _Gradient, _Hessian >::operator!=(), DScalar2< _Scalar, _Gradient, _Hessian >::operator*=(), DScalar2< _Scalar, _Gradient, _Hessian >::operator+=(), DScalar2< _Scalar, _Gradient, _Hessian >::operator+=(), DScalar2< _Scalar, _Gradient, _Hessian >::operator-=(), DScalar2< _Scalar, _Gradient, _Hessian >::operator-=(), DScalar2< _Scalar, _Gradient, _Hessian >::operator/=(), DScalar2< _Scalar, _Gradient, _Hessian >::operator<(), DScalar2< _Scalar, _Gradient, _Hessian >::operator<(), DScalar2< _Scalar, _Gradient, _Hessian >::operator<=(), DScalar2< _Scalar, _Gradient, _Hessian >::operator<=(), DScalar2< _Scalar, _Gradient, _Hessian >::operator=(), DScalar2< _Scalar, _Gradient, _Hessian >::operator=(), DScalar2< _Scalar, _Gradient, _Hessian >::operator==(), DScalar2< _Scalar, _Gradient, _Hessian >::operator>(), DScalar2< _Scalar, _Gradient, _Hessian >::operator>(), DScalar2< _Scalar, _Gradient, _Hessian >::operator>=(), and DScalar2< _Scalar, _Gradient, _Hessian >::operator>=().