8 #ifndef META_OCEAN_MATH_AUTOMATIC_DIFFERENTIATION_H
9 #define META_OCEAN_MATH_AUTOMATIC_DIFFERENTIATION_H
18 template <
typename T,
typename TNumeric>
class AutomaticDifferentiationT;
83 template <
typename T,
typename TNumeric = NumericT<T>>
129 inline const T&
value()
const;
358 template <
typename T,
typename TNumeric>
361 derivative_(value == T(0) ? T(0) : T(1))
367 template <
typename T,
typename TNumeric>
370 derivative_(derivative)
375 template <
typename T,
typename TNumeric>
378 derivative_(isVariable ? T(1) : T(0))
383 template <
typename T,
typename TNumeric>
389 template <
typename T,
typename TNumeric>
395 template <
typename T,
typename TNumeric>
401 template <
typename T,
typename TNumeric>
410 template <
typename T,
typename TNumeric>
417 template <
typename T1,
typename TNumeric1,
typename T2>
426 template <
typename T,
typename TNumeric>
433 template <
typename T,
typename TNumeric>
442 template <
typename T,
typename TNumeric>
449 template <
typename T,
typename TNumeric>
458 template <
typename T,
typename TNumeric>
467 template <
typename T,
typename TNumeric>
476 template <
typename T,
typename TNumeric>
483 template <
typename T1,
typename TNumeric1,
typename T2>
492 template <
typename T,
typename TNumeric>
500 template <
typename T,
typename TNumeric>
503 *
this = *
this * right;
507 template <
typename T,
typename TNumeric>
516 template <
typename T,
typename TNumeric>
523 template <
typename T1,
typename TNumeric1,
typename T2>
532 template <
typename T,
typename TNumeric>
537 ocean_assert((std::is_same<T, float>::value) || TNumeric::isNotEqualEps(right.
value_));
542 template <
typename T,
typename TNumeric>
545 *
this = *
this / right;
549 template <
typename T,
typename TNumeric>
555 ocean_assert((std::is_same<T, float>::value) || TNumeric::isNotEqualEps(right));
560 template <
typename T,
typename TNumeric>
563 ocean_assert((std::is_same<T, float>::value) || TNumeric::isNotEqualEps(right));
566 derivative_ /= right;
571 template <
typename T1,
typename TNumeric1,
typename T2>
582 template <
typename T,
typename TNumeric>
591 template <
typename T,
typename TNumeric>
600 template <
typename T,
typename TNumeric>
609 template <
typename T,
typename TNumeric>
615 ocean_assert(value.
value_ >= T(0));
617 const T sqrtValue = TNumeric::sqrt(value.
value_);
622 template <
typename T,
typename TNumeric>
631 template <
typename T,
typename TNumeric>
637 const T expValue = TNumeric::exp(value.
value_);
642 template <
typename T,
typename TNumeric>
648 ocean_assert((std::is_same<T, float>::value) || TNumeric::isNotEqualEps(value.
value_));
653 template <
typename T,
typename TNumeric>
659 ocean_assert((std::is_same<T, float>::value) || TNumeric::isNotEqualEps(value.
value_));
664 template <
typename T,
typename TNumeric>
670 ocean_assert((std::is_same<T, float>::value) || TNumeric::isNotEqualEps(value.
value_));
675 template <
typename T,
typename TNumeric>
681 ocean_assert(x.
value_ >= T(0));
686 template <
typename T,
typename TNumeric>
695 template <
typename T,
typename TNumeric>
702 if (value.
value_ < second)
712 template <
typename T,
typename TNumeric>
719 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:665
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:623
static AutomaticDifferentiationT< T, TNumeric > abs(const AutomaticDifferentiationT< T, TNumeric > &value)
Determines the derivative of the abs function.
Definition: AutomaticDifferentiation.h:687
static AutomaticDifferentiationT< T, TNumeric > tan(const AutomaticDifferentiationT< T, TNumeric > &value)
Determines the derivative of the tangent function.
Definition: AutomaticDifferentiation.h:601
static AutomaticDifferentiationT< T, TNumeric > max(const AutomaticDifferentiationT< T, TNumeric > &value, const T &second)
Determines the derivative of the max function.
Definition: AutomaticDifferentiation.h:713
const T & derivative() const
Returns the actual derivative of this object.
Definition: AutomaticDifferentiation.h:384
static AutomaticDifferentiationT< T, TNumeric > log(const AutomaticDifferentiationT< T, TNumeric > &value)
Determines the derivative of the natural logarithm.
Definition: AutomaticDifferentiation.h:643
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:676
const T & value() const
Returns the value of this object.
Definition: AutomaticDifferentiation.h:390
AutomaticDifferentiationT< T, TNumeric > & operator+=(const T &right)
Adds a scalar value to this differentiation object.
Definition: AutomaticDifferentiation.h:411
friend AutomaticDifferentiationT< T1, TNumeric1 > operator*(const T2 &left, const AutomaticDifferentiationT< T1, TNumeric1 > &right)
Definition: AutomaticDifferentiation.h:524
static AutomaticDifferentiationT< T, TNumeric > cos(const AutomaticDifferentiationT< T, TNumeric > &value)
Determines the derivative of the cosine function.
Definition: AutomaticDifferentiation.h:592
static AutomaticDifferentiationT< T, TNumeric > sqrt(const AutomaticDifferentiationT< T, TNumeric > &value)
Determines the derivative of the square root function.
Definition: AutomaticDifferentiation.h:610
static AutomaticDifferentiationT< T, TNumeric > log2(const AutomaticDifferentiationT< T, TNumeric > &value)
Determines the derivative of the logarithm to the base 2.
Definition: AutomaticDifferentiation.h:654
T value_
The scalar value of this object.
Definition: AutomaticDifferentiation.h:352
AutomaticDifferentiationT< T, TNumeric > operator-() const
Unary negation operator returns the negative of this differentiation object.
Definition: AutomaticDifferentiation.h:450
friend AutomaticDifferentiationT< T1, TNumeric1 > operator/(const T2 &left, const AutomaticDifferentiationT< T1, TNumeric1 > &right)
Definition: AutomaticDifferentiation.h:572
static AutomaticDifferentiationT< T, TNumeric > min(const AutomaticDifferentiationT< T, TNumeric > &value, const T &second)
Determines the derivative of the min function.
Definition: AutomaticDifferentiation.h:696
AutomaticDifferentiationT< T, TNumeric > & operator-=(const T &right)
Subtracts a scalar value from this differentiation object.
Definition: AutomaticDifferentiation.h:477
friend AutomaticDifferentiationT< T1, TNumeric1 > operator+(const T2 &left, const AutomaticDifferentiationT< T1, TNumeric1 > &right)
Definition: AutomaticDifferentiation.h:418
static AutomaticDifferentiationT< T, TNumeric > sin(const AutomaticDifferentiationT< T, TNumeric > &value)
Determines the derivative of the sinus function.
Definition: AutomaticDifferentiation.h:583
const T & operator()() const
Returns the actual derivative value of this object.
Definition: AutomaticDifferentiation.h:396
static AutomaticDifferentiationT< T, TNumeric > exp(const AutomaticDifferentiationT< T, TNumeric > &value)
Determines the derivative of the exponential function.
Definition: AutomaticDifferentiation.h:632
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:543
AutomaticDifferentiationT< T, TNumeric > & operator*=(const AutomaticDifferentiationT< T, TNumeric > &right)
Multiplies two differentiation objects and determines the product derivative.
Definition: AutomaticDifferentiation.h:501
This class provides basic numeric functionalities.
Definition: Numeric.h:57
unsigned int sqr(const char value)
Returns the square value of a given value.
Definition: base/Utilities.h:1029
AutomaticDifferentiationT< Scalar, Numeric > AutomaticDifferentiation
Definition of a scalar differentiation object using the data type of Scalar as parameter.
Definition: AutomaticDifferentiation.h:18
AutomaticDifferentiationT< float, NumericF > AutomaticDifferentiationF
Definition of a scalar differentiation object using float as data type.
Definition: AutomaticDifferentiation.h:39
AutomaticDifferentiationT< double, NumericD > AutomaticDifferentiationD
Definition of a scalar differentiation object using double as data type.
Definition: AutomaticDifferentiation.h:32
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:484
AutomaticDifferentiationT< T1, TNumeric1 > operator/(const T2 &left, const AutomaticDifferentiationT< T1, TNumeric1 > &right)
Definition: AutomaticDifferentiation.h:572
AutomaticDifferentiationT< T1, TNumeric1 > operator*(const T2 &left, const AutomaticDifferentiationT< T1, TNumeric1 > &right)
Definition: AutomaticDifferentiation.h:524
AutomaticDifferentiationT< T1, TNumeric1 > operator+(const T2 &left, const AutomaticDifferentiationT< T1, TNumeric1 > &right)
Definition: AutomaticDifferentiation.h:418