Theoretica
A C++ numerical and automatic mathematical library
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 
10 namespace theoretica {
11 
12  namespace autodiff {
13 
14 
15  // Type traits for automatic differentiation
16 
17 
19  template<typename Type>
20  struct is_dual_type : std::false_type {};
21 
23  template<>
24  struct is_dual_type<dual> : std::true_type {};
25 
26 
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 
41  template<typename Function, typename T = bool>
43  typename std::enable_if<is_dual_func<Function>::value, T>::type;
44 
45 
47  template<typename Type>
48  struct is_dual2_type : std::false_type {};
49 
51  template<>
52  struct is_dual2_type<dual2> : std::true_type {};
53 
54 
57  template<typename Function>
58  using is_dual2_func =
59  std::conditional_t <
61  typename _internal::return_type_or_void<Function, dual2>::type
62  >::value,
63  std::true_type, std::false_type
64  >;
65 
66 
69  template<typename Function, typename T = bool>
71  typename std::enable_if<is_dual2_func<Function>::value, T>::type;
72 
73 
75  template<typename Type>
76  struct is_multidual_type : std::false_type {};
77 
79  template<unsigned int N>
80  struct is_multidual_type<multidual<N>> : std::true_type {};
81 
84  template<typename Type, typename T = bool>
86  typename std::enable_if<is_multidual_type<Type>::value, T>::type;
87 
88 
93  template<typename Function, typename T = bool>
94  using enable_scalar_field = typename std::enable_if <
96  >::type;
97 
98 
103  template<typename Function, typename T = bool>
104  using enable_vector_field = typename std::enable_if <
107  >::value, T
108  >::type;
109 
110 
111  // Alias types for multivariate automatic differentiation
112 
113 
116  template<unsigned int N = 0>
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 
137 
140  using dvec2 = dvec_t<2>;
141 
142 
146 
149  using dvec3 = dvec_t<3>;
150 
151 
155 
158  using dvec4 = dvec_t<4>;
159  }
160 }
161 
162 #endif
Second order dual number class.
Definition: dual2.h:29
Dual number class.
Definition: dual.h:28
Multidual number algebra for functions of the form .
Definition: multidual.h:26
A statically allocated N-dimensional vector with elements of the given type.
Definition: vec.h:88
typename std::enable_if< is_dual_func< Function >::value, T >::type enable_dual_func
Enable a certain function overload if the given type is a function taking as first argument a dual nu...
Definition: autodiff_types.h:43
typename std::enable_if< is_dual2_func< Function >::value, T >::type enable_dual2_func
Enable a certain function overload if the given type is a function taking as first argument a dual2 n...
Definition: autodiff_types.h:71
typename std::enable_if< is_multidual_type< return_type_t< Function > >::value, T >::type enable_scalar_field
Enable a certain function overload if the given type is a Callable object corresponding to a multidua...
Definition: autodiff_types.h:96
std::conditional_t< is_dual_type< typename _internal::return_type_or_void< Function, dual >::type >::value, std::true_type, std::false_type > is_dual_func
Type trait to check whether the given function takes a dual number as its first argument.
Definition: autodiff_types.h:36
typename std::enable_if< is_multidual_type< vector_element_t< return_type_t< Function > > >::value, T >::type enable_vector_field
Enable a certain function overload if the given type is a Callable object corresponding to a multidua...
Definition: autodiff_types.h:108
typename std::enable_if< is_multidual_type< Type >::value, T >::type enable_multidual
Enable a certain function overload if the given type is an instantiation of the multidual template cl...
Definition: autodiff_types.h:86
std::conditional_t< is_dual2_type< typename _internal::return_type_or_void< Function, dual2 >::type >::value, std::true_type, std::false_type > is_dual2_func
Type trait to check whether the given function takes a dual2 number as its first argument.
Definition: autodiff_types.h:64
Main namespace of the library which contains all functions and objects.
Definition: algebra.h:27
std::remove_reference_t< decltype(std::declval< Structure >()[0])> vector_element_t
Extract the type of a vector (or any indexable container) from its operator[].
Definition: core_traits.h:134
Type trait to check whether the given type is a multidual number.
Definition: autodiff_types.h:48
Type trait to check whether the given type is a multidual number.
Definition: autodiff_types.h:20
Type trait to check whether the given type is a multidual number.
Definition: autodiff_types.h:76