28 template <
typename gradient_type>
59 template <
typename gradient_type>
66 template <
typename gradient_type>
73 template <
typename gradient_type_a,
typename gradient_type_b>
80 template <
typename gradient_type>
87 template <
typename gradient_type>
94 template <
typename gradient_type>
101 template <
typename gradient_type_a,
typename gradient_type_b>
108 template <
typename gradient_type>
115 template <
typename gradient_type>
122 template <
typename gradient_type_a,
typename gradient_type_b>
129 template <
typename gradient_type>
136 template <
typename gradient_type>
143 template <
typename gradient_type_a,
typename gradient_type_b>
154 #define binary_comparator_overload(x) \
155 template <typename T> \
156 SERAC_HOST_DEVICE constexpr bool operator x(const dual<T>& a, double b) \
158 return a.value x b; \
161 template <typename T> \
162 SERAC_HOST_DEVICE constexpr bool operator x(double a, const dual<T>& b) \
164 return a x b.value; \
167 template <typename T, typename U> \
168 SERAC_HOST_DEVICE constexpr bool operator x(const dual<T>& a, const dual<U>& b) \
170 return a.value x b.value; \
179 #undef binary_comparator_overload
182 template <
typename gradient_type>
191 template <
typename gradient_type>
200 template <
typename gradient_type>
208 template <
typename gradient_type>
219 template <
typename gradient_type>
222 return (x.
value >= 0) ? x : -x;
229 template <
typename gradient_type>
233 return (a > b_dual) ? a : b_dual;
237 template <
typename gradient_type>
241 return (a_dual > b) ? a_dual : b;
245 template <
typename gradient_type>
248 return (a > b) ? a : b;
255 template <
typename gradient_type>
259 return (a < b_dual) ? a : b_dual;
263 template <
typename gradient_type>
267 return (a_dual < b) ? a_dual : b;
271 template <
typename gradient_type>
274 return (a < b) ? a : b;
278 template <
typename gradient_type>
286 template <
typename gradient_type>
294 template <
typename gradient_type>
302 template <
typename gradient_type>
310 template <
typename gradient_type>
319 template <
typename gradient_type>
327 template <
typename gradient_type>
335 template <
typename gradient_type>
343 template <
typename gradient_type>
351 template <
typename gradient_type>
359 template <
typename gradient_type>
367 template <
typename gradient_type>
375 template <
typename gradient_type>
385 template <
typename gradient_type>
394 template <
typename gradient_type>
404 template <
typename T,
int... n>
415 template <
typename T>
422 template <
typename T>
429 template <
typename gradient_type>
436 template <
typename T>
438 static constexpr
bool value =
false;
442 template <
typename T>
449 #include "serac/numerics/functional/tuple_tensor_dual_functions.hpp"
This file contains the interface used for initializing/terminating any hardware accelerator-related f...
#define SERAC_HOST_DEVICE
Macro that evaluates to __host__ __device__ when compiling with nvcc and does nothing on a host compi...
Accelerator functionality.
constexpr SERAC_HOST_DEVICE auto make_dual(double x)
promote a value to a dual number of the appropriate type
SERAC_HOST_DEVICE auto atan2(dual< gradient_type > y, dual< gradient_type > x)
implementation of atan2 for dual numbers
SERAC_HOST_DEVICE auto sin(dual< gradient_type > a)
implementation of sine for dual numbers
constexpr SERAC_HOST_DEVICE auto operator*(const dual< gradient_type > &a, double b)
multiplication of a dual number and a non-dual number
SERAC_HOST_DEVICE auto cos(dual< gradient_type > a)
implementation of cosine for dual numbers
SERAC_HOST_DEVICE auto pow(dual< gradient_type > a, double b)
implementation of a (dual) raised to the b (non-dual) power
Domain operator-(const Domain &a, const Domain &b)
create a new domain that is the set difference of a and b
SERAC_HOST_DEVICE auto pow(dual< gradient_type > a, dual< gradient_type > b)
implementation of a (dual) raised to the b (dual) power
SERAC_HOST_DEVICE auto max(dual< gradient_type > a, double b)
Implementation of max for dual numbers.
SERAC_HOST_DEVICE auto min(dual< gradient_type > a, double b)
Implementation of min for dual numbers.
SERAC_HOST_DEVICE auto sqrt(dual< gradient_type > x)
implementation of square root for dual numbers
constexpr SERAC_HOST_DEVICE auto operator+(dual< gradient_type > a, double b)
addition of a dual number and a non-dual number
constexpr SERAC_HOST_DEVICE auto & operator-=(dual< gradient_type > &a, const dual< gradient_type > &b)
compound assignment (-) for dual numbers
SERAC_HOST_DEVICE auto asin(dual< gradient_type > a)
implementation of asin for dual numbers
constexpr SERAC_HOST_DEVICE auto get_value(const T &arg)
return the "value" part from a given type. For non-dual types, this is just the identity function
auto & operator<<(std::ostream &out, dual< T > A)
overload of operator<< for dual to work with std::cout and other std::ostreams
SERAC_HOST_DEVICE auto abs(dual< gradient_type > x)
Implementation of absolute value function for dual numbers.
SERAC_HOST_DEVICE auto acos(dual< gradient_type > a)
implementation of acos for dual numbers
constexpr SERAC_HOST_DEVICE auto & operator+=(dual< gradient_type > &a, const dual< gradient_type > &b)
compound assignment (+) for dual numbers
SERAC_HOST_DEVICE auto atan(dual< gradient_type > a)
implementation of atan for dual numbers
SERAC_HOST_DEVICE auto log(dual< gradient_type > a)
implementation of the natural logarithm function for dual numbers
SERAC_HOST_DEVICE auto atan2(dual< gradient_type > y, double x)
implementation of atan2 for dual numbers
constexpr SERAC_HOST_DEVICE auto get_gradient(dual< gradient_type > arg)
return the "gradient" part from a dual number type
binary_comparator_overload(<)
implement operator< for dual numbers
constexpr SERAC_HOST_DEVICE auto operator/(const dual< gradient_type > &a, double b)
division of a dual number by a non-dual number
SERAC_HOST_DEVICE auto log1p(dual< gradient_type > a)
implementation of the natural logarithm of one plus the argument function for dual numbers
dual(double, T) -> dual< T >
class template argument deduction guide for type dual.
SERAC_HOST_DEVICE auto exp(dual< gradient_type > a)
implementation of exponential function for dual numbers
Dual number struct (value plus gradient)
gradient_type gradient
the partial derivatives of value w.r.t. some other quantity
constexpr SERAC_HOST_DEVICE auto & operator=(double b)
Copy assignment operator.
double value
the actual numerical value
class for checking if a type is a dual number or not
static constexpr bool value
whether or not type T is a dual number