sigma  1.0.0
Loading...
Searching...
No Matches
operation_common.hpp
Go to the documentation of this file.
1#pragma once
4
8
9namespace sigma::detail_ {
10
12constexpr double pi = 3.14159265358979323846;
13
23template<typename T>
24void inplace_unary(Uncertain<T>& c, T mean, T dcda) {
26 c_setter.update_mean(mean);
27 c_setter.update_derivatives(dcda);
28}
29
42template<typename T>
43Uncertain<T> unary_result(const Uncertain<T>& a, T mean, T dcda) {
44 Uncertain<T> c(a);
45 detail_::inplace_unary(c, mean, dcda);
46 return c;
47}
48
60template<typename T>
61void inplace_binary(Uncertain<T>& c, const Uncertain<T>& b, T mean, T dcda,
62 T dcdb) {
64 c_setter.update_mean(mean);
65 c_setter.update_derivatives(dcda);
66 c_setter.update_derivatives(b.deps(), dcdb);
67}
68
80template<typename FunctionType, typename NumericType>
81NumericType numeric_derivative(FunctionType f, NumericType a) {
82 // Step and step size chosen for consistency with uncertainties package
83 auto step_size = std::sqrt(std::numeric_limits<float>::epsilon());
84 auto step = step_size * std::abs(a);
85 auto a_plus = f(a + step);
86 auto a_minus = f(a - step);
87 auto dcda = (a_plus - a_minus) / (2 * step);
88 return dcda;
89}
90
91} // namespace sigma::detail_
Models an unceratin variable.
Definition uncertain.hpp:34
const deps_map_t & deps() const
Get the dependencies of the variable.
Definition uncertain.hpp:87
Modifies an unceratin variable.
Definition setter.hpp:20
void update_derivatives(value_t dxda)
Update of existing derivatives.
Definition setter.hpp:90
void update_mean(value_t mean)
Update the mean of the wrapped variable.
Definition setter.hpp:61
The namespace that contains the implementation details of the library.
void inplace_binary(Uncertain< T > &c, const Uncertain< T > &b, T mean, T dcda, T dcdb)
Generalized Inplace Binary Changes.
Definition operation_common.hpp:61
void inplace_unary(Uncertain< T > &c, T mean, T dcda)
Generalized Inplace Unary Changes.
Definition operation_common.hpp:24
constexpr double pi
Value of Pi.
Definition operation_common.hpp:12
Uncertain< T > unary_result(const Uncertain< T > &a, T mean, T dcda)
Generalized Unary Changes.
Definition operation_common.hpp:43
NumericType numeric_derivative(FunctionType f, NumericType a)
Compute the numeric derivative of a function.
Definition operation_common.hpp:81
Defines the Setter class.
Defines the Uncertain class.