Theoretica
Mathematical Library
Loading...
Searching...
No Matches
autodiff_types.h
Go to the documentation of this file.
1
5
6#ifndef THEORETICA_AUTODIFF_TYPES_H
7#define THEORETICA_AUTODIFF_TYPES_H
8
9
10namespace theoretica {
11
12 namespace autodiff {
13
14
15 // Type traits for automatic differentiation
16
17
18 // Type trait to check whether the given type is a multidual number
19 template<typename Type>
20 struct is_dual_type : std::false_type {};
21
22
23 template<>
24 struct is_dual_type<dual> : std::true_type {};
25
26
27 // Type trait to check whether the given function takes
28 // a dual number as its first argument.
29 template<typename Function>
30 using is_dual_func =
31 std::conditional_t <
32 is_dual_type <
33 typename _internal::return_type_or_void<Function, dual>::type
34 >::value,
35 std::true_type, std::false_type
36 >;
37
38
39 // Enable a certain function overload if the given type
40 // is a function taking as first argument a dual number
41 template<typename Function, typename T = bool>
42 using enable_dual_func =
43 typename std::enable_if<is_dual_func<Function>::value, T>::type;
44
45
46 // Type trait to check whether the given type is a multidual number
47 template<typename Type>
48 struct is_dual2_type : std::false_type {};
49
50
51 template<>
52 struct is_dual2_type<dual2> : std::true_type {};
53
54
55 // Type trait to check whether the given function takes
56 // a dual2 number as its first argument.
57 template<typename Function>
58 using is_dual2_func =
59 std::conditional_t <
60 is_dual2_type <
61 typename _internal::return_type_or_void<Function, dual2>::type
62 >::value,
63 std::true_type, std::false_type
64 >;
65
66
67 // Enable a certain function overload if the given type
68 // is a function taking as first argument a dual2 number
69 template<typename Function, typename T = bool>
70 using enable_dual2_func =
71 typename std::enable_if<is_dual2_func<Function>::value, T>::type;
72
73
74 // Type trait to check whether the given type is a multidual number
75 template<typename Type>
76 struct is_multidual_type : std::false_type {};
77
78
79 template<unsigned int N>
80 struct is_multidual_type<multidual<N>> : std::true_type {};
81
82 // Enable a certain function overload if the given type
83 // is an instantiation of the multidual template class
84 template<typename Type, typename T = bool>
85 using enable_multidual =
86 typename std::enable_if<is_multidual_type<Type>::value, T>::type;
87
88
89 // Enable a certain function overload if the given type
90 // is a Callable object corresponding to a multidual function
91 // representing a scalar field, that is, a function taking
92 // a dvec_t and returning a dreal_t.
93 template<typename Function, typename T = bool>
94 using enable_scalar_field = typename std::enable_if <
95 is_multidual_type<return_type_t<Function>>::value, T
96 >::type;
97
98
99 // Enable a certain function overload if the given type
100 // is a Callable object corresponding to a multidual function
101 // representing a vector field, that is, a function taking
102 // a dvec_t and returning a dvec_t.
103 template<typename Function, typename T = bool>
104 using enable_vector_field = typename std::enable_if <
105 is_multidual_type <
106 vector_element_t<return_type_t<Function>>
107 >::value, T
108 >::type;
109
110
111 // Alias types for multivariate automatic differentiation
112
113
116 template<unsigned int N = 0>
117 using dreal_t = multidual<N>;
118
121 template<unsigned int N = 0>
122 using dvec_t = vec<dreal_t<N>, N>;
123
124
127 using dreal = dreal_t<0>;
128
131 using dvec = dvec_t<0>;
132
133
136 using dreal2 = dreal_t<2>;
137
140 using dvec2 = dvec_t<2>;
141
142
145 using dreal3 = dreal_t<3>;
146
149 using dvec3 = dvec_t<3>;
150
151
154 using dreal4 = dreal_t<4>;
155
158 using dvec4 = dvec_t<4>;
159 }
160}
161
162#endif
multidual< N > dreal_t
Real type for multivariate automatic differentiation (read "differential real").
Definition autodiff_types.h:117
dvec_t< 2 > dvec2
Vector type for multivariate automatic differentiation with two-dimensional statically allocated vect...
Definition autodiff_types.h:140
dvec_t< 0 > dvec
Vector type for multivariate automatic differentiation with dynamically allocated vectors.
Definition autodiff_types.h:131
dreal_t< 4 > dreal4
Real type for multivariate automatic differentiation with four-dimensional statically allocated vecto...
Definition autodiff_types.h:154
dreal_t< 0 > dreal
Real type for multivariate automatic differentiation with dynamically allocated vectors.
Definition autodiff_types.h:127
dreal_t< 2 > dreal2
Real type for multivariate automatic differentiation with two-dimensional statically allocated vector...
Definition autodiff_types.h:136
vec< dreal_t< N >, N > dvec_t
Vector type for multivariate automatic differentiation (read "differential vector").
Definition autodiff_types.h:122
dvec_t< 3 > dvec3
Vector type for multivariate automatic differentiation with three-dimensional statically allocated ve...
Definition autodiff_types.h:149
dvec_t< 4 > dvec4
Vector type for multivariate automatic differentiation with four-dimensional statically allocated vec...
Definition autodiff_types.h:158
dreal_t< 3 > dreal3
Real type for multivariate automatic differentiation with three-dimensional statically allocated vect...
Definition autodiff_types.h:145
Main namespace of the library which contains all functions and objects.
Definition algebra.h:27