Mundy: Multibody Nonlocal Dynamics Version of the Day
Loading...
Searching...
No Matches
AutoDiffScalar.hpp File Reference

A forward-mode automatic-differentiation scalar: carries a value and its derivatives. More...

Classes

class  mundy::AutoDiffScalar< T, N >
 A forward-mode autodiff scalar over passive real type T with N tracked derivatives. More...
struct  mundy::NumTraits< AutoDiffScalar< T, N > >
 Numeric traits for AutoDiffScalar. Numeric values come from the passive type; the related types remain differentiable. More...
struct  mundy::ScalarBinaryOpTraits< AutoDiffScalar< T, N >, T, Op >
 An AutoDiffScalar combined with its passive type yields an AutoDiffScalar (either order). More...
struct  mundy::ScalarBinaryOpTraits< T, AutoDiffScalar< T, N >, Op >

Namespaces

namespace  mundy

Functions

Passive-value arithmetic (passive op AutoDiffScalar)
template<typename T, size_t N>
constexpr AutoDiffScalar< T, Nmundy::operator+ (const T &s, const AutoDiffScalar< T, N > &a)
template<typename T, size_t N>
constexpr AutoDiffScalar< T, Nmundy::operator- (const T &s, const AutoDiffScalar< T, N > &a)
template<typename T, size_t N>
constexpr AutoDiffScalar< T, Nmundy::operator* (const T &s, const AutoDiffScalar< T, N > &a)
template<typename T, size_t N>
constexpr AutoDiffScalar< T, Nmundy::operator/ (const T &s, const AutoDiffScalar< T, N > &a)
Comparisons (by value)
template<typename T, size_t N>
constexpr bool mundy::operator== (const AutoDiffScalar< T, N > &a, const AutoDiffScalar< T, N > &b)
template<typename T, size_t N>
constexpr bool mundy::operator!= (const AutoDiffScalar< T, N > &a, const AutoDiffScalar< T, N > &b)
template<typename T, size_t N>
constexpr bool mundy::operator< (const AutoDiffScalar< T, N > &a, const AutoDiffScalar< T, N > &b)
template<typename T, size_t N>
constexpr bool mundy::operator<= (const AutoDiffScalar< T, N > &a, const AutoDiffScalar< T, N > &b)
template<typename T, size_t N>
constexpr bool mundy::operator> (const AutoDiffScalar< T, N > &a, const AutoDiffScalar< T, N > &b)
template<typename T, size_t N>
constexpr bool mundy::operator>= (const AutoDiffScalar< T, N > &a, const AutoDiffScalar< T, N > &b)
template<typename T, size_t N>
constexpr bool mundy::operator== (const AutoDiffScalar< T, N > &a, const T &b)
template<typename T, size_t N>
constexpr bool mundy::operator!= (const AutoDiffScalar< T, N > &a, const T &b)
template<typename T, size_t N>
constexpr bool mundy::operator< (const AutoDiffScalar< T, N > &a, const T &b)
template<typename T, size_t N>
constexpr bool mundy::operator<= (const AutoDiffScalar< T, N > &a, const T &b)
template<typename T, size_t N>
constexpr bool mundy::operator> (const AutoDiffScalar< T, N > &a, const T &b)
template<typename T, size_t N>
constexpr bool mundy::operator>= (const AutoDiffScalar< T, N > &a, const T &b)
template<typename T, size_t N>
constexpr bool mundy::operator== (const T &a, const AutoDiffScalar< T, N > &b)
template<typename T, size_t N>
constexpr bool mundy::operator!= (const T &a, const AutoDiffScalar< T, N > &b)
template<typename T, size_t N>
constexpr bool mundy::operator< (const T &a, const AutoDiffScalar< T, N > &b)
template<typename T, size_t N>
constexpr bool mundy::operator<= (const T &a, const AutoDiffScalar< T, N > &b)
template<typename T, size_t N>
constexpr bool mundy::operator> (const T &a, const AutoDiffScalar< T, N > &b)
template<typename T, size_t N>
constexpr bool mundy::operator>= (const T &a, const AutoDiffScalar< T, N > &b)
Math overloads (value via the mundy:: dispatch, derivative via the chain rule)
template<typename T, size_t N>
constexpr AutoDiffScalar< T, Nmundy::sqrt (const AutoDiffScalar< T, N > &x)
template<typename T, size_t N>
constexpr AutoDiffScalar< T, Nmundy::exp (const AutoDiffScalar< T, N > &x)
template<typename T, size_t N>
constexpr AutoDiffScalar< T, Nmundy::log (const AutoDiffScalar< T, N > &x)
template<typename T, size_t N>
constexpr AutoDiffScalar< T, Nmundy::sin (const AutoDiffScalar< T, N > &x)
template<typename T, size_t N>
constexpr AutoDiffScalar< T, Nmundy::cos (const AutoDiffScalar< T, N > &x)
template<typename T, size_t N>
constexpr AutoDiffScalar< T, Nmundy::acos (const AutoDiffScalar< T, N > &x)
template<typename T, size_t N>
constexpr AutoDiffScalar< T, Nmundy::abs (const AutoDiffScalar< T, N > &x)
template<typename T, size_t N>
constexpr AutoDiffScalar< T, Nmundy::pow (const AutoDiffScalar< T, N > &x, const T &p)
 Power with a passive exponent: d/dx x^p = p x^(p-1).
template<typename T, size_t N>
constexpr AutoDiffScalar< T, Nmundy::atan2 (const AutoDiffScalar< T, N > &y, const AutoDiffScalar< T, N > &x)
 Two-argument arctangent: d atan2(y,x) = (x dy - y dx) / (x^2 + y^2).
template<typename T, size_t N>
constexpr AutoDiffScalar< T, Nmundy::copysign (const AutoDiffScalar< T, N > &x, const T &s)
 Copy the sign of a passive value onto x; scales the derivative by the resulting sign flip.
template<typename T, size_t N>
constexpr AutoDiffScalar< T, Nmundy::copysign (const AutoDiffScalar< T, N > &x, const AutoDiffScalar< T, N > &s)
 Copy the sign of another AutoDiffScalar onto x; the sign source contributes no derivative.
template<typename T, size_t N>
constexpr AutoDiffScalar< T, Nmundy::min (const AutoDiffScalar< T, N > &a, const AutoDiffScalar< T, N > &b)
template<typename T, size_t N>
constexpr AutoDiffScalar< T, Nmundy::max (const AutoDiffScalar< T, N > &a, const AutoDiffScalar< T, N > &b)
template<typename T, size_t N>
constexpr AutoDiffScalar< T, Nmundy::min (const AutoDiffScalar< T, N > &a, const T &b)
template<typename T, size_t N>
constexpr AutoDiffScalar< T, Nmundy::max (const AutoDiffScalar< T, N > &a, const T &b)
template<typename T, size_t N>
constexpr AutoDiffScalar< T, Nmundy::min (const T &a, const AutoDiffScalar< T, N > &b)
template<typename T, size_t N>
constexpr AutoDiffScalar< T, Nmundy::max (const T &a, const AutoDiffScalar< T, N > &b)
template<typename T, size_t N>
std::ostream & mundy::operator<< (std::ostream &os, const AutoDiffScalar< T, N > &a)
 Stream as "value [d0, d1, ...]".

Detailed Description

AutoDiffScalar is a drop-in scalar that propagates first derivatives by the chain rule. It satisfies the MundyMath custom-scalar contract — NumTraits, ScalarBinaryOpTraits, and ADL math overloads — so it can stand in for a primitive scalar throughout the library.

AutoDiffScalar<double, 2> x(3.0, 0); // independent variable, d/dx seeded at slot 0
AutoDiffScalar<double, 2> y(4.0, 1); // independent variable, d/dy seeded at slot 1
auto f = x * y + sqrt(x); // f.value() == 12 + sqrt(3)
f.derivatives()[0]; // df/dx == y + 0.5/sqrt(x)
f.derivatives()[1]; // df/dy == x