8#ifndef META_OCEAN_MATH_AUTOMATIC_DIFFERENTIATION_H
9#define META_OCEAN_MATH_AUTOMATIC_DIFFERENTIATION_H
18template <
typename T,
typename TNumeric>
class AutomaticDifferentiationT;
83template <
typename T,
typename TNumeric = NumericT<T>>
129 inline const T&
value()
const;
358template <
typename T,
typename TNumeric>
366template <
typename T,
typename TNumeric>
369 derivative_(derivative)
374template <
typename T,
typename TNumeric>
377 derivative_(isVariable ? T(1) : T(0))
382template <
typename T,
typename TNumeric>
388template <
typename T,
typename TNumeric>
394template <
typename T,
typename TNumeric>
400template <
typename T,
typename TNumeric>
409template <
typename T,
typename TNumeric>
416template <
typename T1,
typename TNumeric1,
typename T2>
425template <
typename T,
typename TNumeric>
432template <
typename T,
typename TNumeric>
441template <
typename T,
typename TNumeric>
448template <
typename T,
typename TNumeric>
457template <
typename T,
typename TNumeric>
466template <
typename T,
typename TNumeric>
475template <
typename T,
typename TNumeric>
482template <
typename T1,
typename TNumeric1,
typename T2>
491template <
typename T,
typename TNumeric>
499template <
typename T,
typename TNumeric>
502 *
this = *
this * right;
506template <
typename T,
typename TNumeric>
515template <
typename T,
typename TNumeric>
522 derivative_ *= right;
527template <
typename T1,
typename TNumeric1,
typename T2>
536template <
typename T,
typename TNumeric>
541 ocean_assert((std::is_same<T, float>::value) || TNumeric::isNotEqualEps(right.
value_));
546template <
typename T,
typename TNumeric>
549 *
this = *
this / right;
553template <
typename T,
typename TNumeric>
559 ocean_assert((std::is_same<T, float>::value) || TNumeric::isNotEqualEps(right));
564template <
typename T,
typename TNumeric>
567 ocean_assert((std::is_same<T, float>::value) || TNumeric::isNotEqualEps(right));
570 derivative_ /= right;
575template <
typename T1,
typename TNumeric1,
typename T2>
586template <
typename T,
typename TNumeric>
595template <
typename T,
typename TNumeric>
604template <
typename T,
typename TNumeric>
613template <
typename T,
typename TNumeric>
619 ocean_assert(value.
value_ >= T(0));
621 const T sqrtValue = TNumeric::sqrt(value.
value_);
626template <
typename T,
typename TNumeric>
635template <
typename T,
typename TNumeric>
641 const T expValue = TNumeric::exp(value.
value_);
646template <
typename T,
typename TNumeric>
652 ocean_assert((std::is_same<T, float>::value) || TNumeric::isNotEqualEps(value.
value_));
657template <
typename T,
typename TNumeric>
663 ocean_assert((std::is_same<T, float>::value) || TNumeric::isNotEqualEps(value.
value_));
668template <
typename T,
typename TNumeric>
674 ocean_assert((std::is_same<T, float>::value) || TNumeric::isNotEqualEps(value.
value_));
679template <
typename T,
typename TNumeric>
685 ocean_assert(x.
value_ >= T(0));
690template <
typename T,
typename TNumeric>
699template <
typename T,
typename TNumeric>
706 if (value.
value_ < second)
716template <
typename T,
typename TNumeric>
723 if (value.
value_ > second)
This class implements an automatic differentiation functionality.
Definition AutomaticDifferentiation.h:85
static AutomaticDifferentiationT< T, TNumeric > log10(const AutomaticDifferentiationT< T, TNumeric > &value)
Determines the derivative of the logarithm to the base 10.
Definition AutomaticDifferentiation.h:669
T derivative_
The actual derivative of this object.
Definition AutomaticDifferentiation.h:355
static AutomaticDifferentiationT< T, TNumeric > sqr(const AutomaticDifferentiationT< T, TNumeric > &value)
Determines the derivative of the square function.
Definition AutomaticDifferentiation.h:627
static AutomaticDifferentiationT< T, TNumeric > abs(const AutomaticDifferentiationT< T, TNumeric > &value)
Determines the derivative of the abs function.
Definition AutomaticDifferentiation.h:691
static AutomaticDifferentiationT< T, TNumeric > tan(const AutomaticDifferentiationT< T, TNumeric > &value)
Determines the derivative of the tangent function.
Definition AutomaticDifferentiation.h:605
static AutomaticDifferentiationT< T, TNumeric > max(const AutomaticDifferentiationT< T, TNumeric > &value, const T &second)
Determines the derivative of the max function.
Definition AutomaticDifferentiation.h:717
const T & derivative() const
Returns the actual derivative of this object.
Definition AutomaticDifferentiation.h:383
static AutomaticDifferentiationT< T, TNumeric > log(const AutomaticDifferentiationT< T, TNumeric > &value)
Determines the derivative of the natural logarithm.
Definition AutomaticDifferentiation.h:647
static AutomaticDifferentiationT< T, TNumeric > pow(const AutomaticDifferentiationT< T, TNumeric > &x, const T &y)
Determines the derivative of the power function calculating x to the power of y.
Definition AutomaticDifferentiation.h:680
friend AutomaticDifferentiationT< T1, TNumeric1 > operator-(const T2 &left, const AutomaticDifferentiationT< T1, TNumeric1 > &right)
Definition AutomaticDifferentiation.h:483
const T & value() const
Returns the value of this object.
Definition AutomaticDifferentiation.h:389
AutomaticDifferentiationT< T, TNumeric > & operator+=(const T &right)
Adds a scalar value to this differentiation object.
Definition AutomaticDifferentiation.h:410
static AutomaticDifferentiationT< T, TNumeric > cos(const AutomaticDifferentiationT< T, TNumeric > &value)
Determines the derivative of the cosine function.
Definition AutomaticDifferentiation.h:596
static AutomaticDifferentiationT< T, TNumeric > sqrt(const AutomaticDifferentiationT< T, TNumeric > &value)
Determines the derivative of the square root function.
Definition AutomaticDifferentiation.h:614
static AutomaticDifferentiationT< T, TNumeric > log2(const AutomaticDifferentiationT< T, TNumeric > &value)
Determines the derivative of the logarithm to the base 2.
Definition AutomaticDifferentiation.h:658
friend AutomaticDifferentiationT< T1, TNumeric1 > operator+(const T2 &left, const AutomaticDifferentiationT< T1, TNumeric1 > &right)
Definition AutomaticDifferentiation.h:417
T value_
The scalar value of this object.
Definition AutomaticDifferentiation.h:352
static AutomaticDifferentiationT< T, TNumeric > min(const AutomaticDifferentiationT< T, TNumeric > &value, const T &second)
Determines the derivative of the min function.
Definition AutomaticDifferentiation.h:700
AutomaticDifferentiationT< T, TNumeric > & operator-=(const T &right)
Subtracts a scalar value from this differentiation object.
Definition AutomaticDifferentiation.h:476
static AutomaticDifferentiationT< T, TNumeric > sin(const AutomaticDifferentiationT< T, TNumeric > &value)
Determines the derivative of the sinus function.
Definition AutomaticDifferentiation.h:587
const T & operator()() const
Returns the actual derivative value of this object.
Definition AutomaticDifferentiation.h:395
static AutomaticDifferentiationT< T, TNumeric > exp(const AutomaticDifferentiationT< T, TNumeric > &value)
Determines the derivative of the exponential function.
Definition AutomaticDifferentiation.h:636
friend AutomaticDifferentiationT< T1, TNumeric1 > operator/(const T2 &left, const AutomaticDifferentiationT< T1, TNumeric1 > &right)
Definition AutomaticDifferentiation.h:576
AutomaticDifferentiationT()=default
Creates a new differentiation object without initializing the parameters.
AutomaticDifferentiationT< T, TNumeric > & operator/=(const AutomaticDifferentiationT< T, TNumeric > &right)
Divides two differentiation objects and determines the quotient derivative.
Definition AutomaticDifferentiation.h:547
AutomaticDifferentiationT< T, TNumeric > & operator*=(const AutomaticDifferentiationT< T, TNumeric > &right)
Multiplies two differentiation objects and determines the product derivative.
Definition AutomaticDifferentiation.h:500
friend AutomaticDifferentiationT< T1, TNumeric1 > operator*(const T2 &left, const AutomaticDifferentiationT< T1, TNumeric1 > &right)
Definition AutomaticDifferentiation.h:528
This class provides basic numeric functionalities.
Definition Numeric.h:57
The namespace covering the entire Ocean framework.
Definition Accessor.h:15
AutomaticDifferentiationT< T1, TNumeric1 > operator*(const T2 &left, const AutomaticDifferentiationT< T1, TNumeric1 > &right)
Definition AutomaticDifferentiation.h:528
AutomaticDifferentiationT< T1, TNumeric1 > operator+(const T2 &left, const AutomaticDifferentiationT< T1, TNumeric1 > &right)
Definition AutomaticDifferentiation.h:417
AutomaticDifferentiationT< T1, TNumeric1 > operator/(const T2 &left, const AutomaticDifferentiationT< T1, TNumeric1 > &right)
Definition AutomaticDifferentiation.h:576
AutomaticDifferentiationT< T1, TNumeric1 > operator-(const T2 &left, const AutomaticDifferentiationT< T1, TNumeric1 > &right)
Definition AutomaticDifferentiation.h:483