antioch-0.4.0
eigen_utils_decl.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // Antioch - A Gas Dynamics Thermochemistry Library
5 //
6 // Copyright (C) 2014-2016 Paul T. Bauman, Benjamin S. Kirk,
7 // Sylvain Plessis, Roy H. Stonger
8 //
9 // Copyright (C) 2013 The PECOS Development Team
10 //
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the Version 2.1 GNU Lesser General
13 // Public License as published by the Free Software Foundation.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
23 // Boston, MA 02110-1301 USA
24 //
25 //-----------------------------------------------------------------------el-
26 
27 #ifndef ANTIOCH_EIGEN_UTILS_DECL_H
28 #define ANTIOCH_EIGEN_UTILS_DECL_H
29 
30 #ifdef ANTIOCH_METAPROGRAMMING_H
31 # error eigen_utils_decl.h must be included before metaprogramming.h
32 #endif
33 
34 #include "antioch_config.h"
35 #include "metaprogramming_decl.h"
36 
37 #include <type_traits> // std::enable_if
38 
39 #ifdef ANTIOCH_HAVE_EIGEN
40 // While this logic is Eigen-specific, these forward declarations deliberately
41 // do not require <Eigen/Dense> to be included. This choice permits mixing
42 // header-only Eigen with header-only Antioch without configure-time flags.
43 #endif
44 
45 // Forward declarations
46 namespace Eigen {
47 template<typename Derived, typename ThenDerived, typename ElseDerived>
48 class Select;
49 }
50 
51 // We want this code to apply to Eigen matrices, arrays, and
52 // expression templates
53 
54 namespace Antioch {
55 
56 template <typename T>
57 struct is_eigen {
58  static const bool value = false;
59 };
60 
61 // FIXME: need to add specializations for expression template types
62 template <typename T>
63 struct state_type<T, typename enable_if_c<is_eigen<T>::value,void>::type> {
64  typedef T type;
65 };
66 
67 // Class to allow tag dispatching to Eigen specializations
69 
70 template <
71  template <typename, int, int, int, int, int> class _Matrix,
72  typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols
73 >
74 struct is_eigen
75 <_Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
76 {
77  static const bool value = true;
78 };
79 
80 
81 }
82 
84 
85 namespace std
86 {
87 
88 template <
89  template <typename, int, int, int, int, int> class _Matrix,
90  typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols
91 >
92 inline
93 ANTIOCH_AUTO(_Matrix<_Scalar ANTIOCH_COMMA _Rows ANTIOCH_COMMA _Cols ANTIOCH_COMMA _Options ANTIOCH_COMMA _MaxRows ANTIOCH_COMMA _MaxCols>)
94 max(const _Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> & a,
95  const _Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> & b)
96 ANTIOCH_RETURNEXPR(_Matrix<_Scalar ANTIOCH_COMMA _Rows ANTIOCH_COMMA _Cols ANTIOCH_COMMA _Options ANTIOCH_COMMA _MaxRows ANTIOCH_COMMA _MaxCols>,
97 a.array().max(b.array()));
98 
99 template <
100  template <typename, int, int, int, int, int> class _Matrix,
101  typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols
102 >
103 inline
104 ANTIOCH_AUTO(_Matrix<_Scalar ANTIOCH_COMMA _Rows ANTIOCH_COMMA _Cols ANTIOCH_COMMA _Options ANTIOCH_COMMA _MaxRows ANTIOCH_COMMA _MaxCols>)
105 min(const _Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> & a,
106  const _Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> & b)
107 ANTIOCH_RETURNEXPR(_Matrix<_Scalar ANTIOCH_COMMA _Rows ANTIOCH_COMMA _Cols ANTIOCH_COMMA _Options ANTIOCH_COMMA _MaxRows ANTIOCH_COMMA _MaxCols>,
108 a.array().min(b.array()));
109 
110 } // end namespace std
111 
112 
113 namespace Antioch
114 {
115 template <typename T>
116 struct tag_type<T,
117  typename std::enable_if<is_eigen<T>::value>::type
118 >
119 {
121 };
122 
123 template <
124  template <typename, int, int, int, int, int> class _Matrix,
125  typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols,
126  typename NewScalar
127 >
128 struct rebind<_Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>, NewScalar>
129 {
130  typedef _Matrix<NewScalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> type;
131 };
132 
133 template <typename T>
134 struct has_size<T, typename Antioch::enable_if_c<is_eigen<T>::value,void>::type>;
135 
136 template <typename T>
137 struct return_auto<T, typename Antioch::enable_if_c<is_eigen<T>::value,void>::type>;
138 
139 template <typename T>
140 struct size_type<T, typename Antioch::enable_if_c<is_eigen<T>::value,void>::type>;
141 
142 // FIXME - we need value_type defined for expression templates too
143 template <
144  template <typename, int, int, int, int, int> class _Matrix,
145  typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols
146 >
147 struct value_type<_Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >;
148 
149 template <
150  template <typename, int, int, int, int, int> class _Matrix,
151  typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols
152 >
153 struct raw_value_type<_Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >;
154 
155 template <typename T>
156 inline
157 typename Antioch::enable_if_c<is_eigen<T>::value,
158  typename value_type<T>::type
159  >::type
160 max(const T& in);
161 
162 template <typename T>
163 inline
164 typename Antioch::enable_if_c<is_eigen<T>::value,
165  typename value_type<T>::type
166  >::type
167 min(const T& in);
168 
169 template <
170  template <typename, int, int, int, int, int> class _Matrix,
171  typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols
172 >
173 inline
174 _Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>
175 zero_clone(const _Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& ex);
176 
177 template <
178  template <typename, int, int, int, int, int> class _Matrix,
179  typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols,
180  typename Scalar2
181 >
182 inline
183 void
184 zero_clone(_Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& output,
185  const _Matrix<Scalar2, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& ex);
186 
187 template <
188  template <typename, int, int, int, int, int> class _Matrix,
189  typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols,
190  typename Scalar
191 >
192 inline
193 _Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>
194 constant_clone(const _Matrix<_Scalar, _Rows, _Cols, _Options,
195  _MaxRows, _MaxCols>& ex,
196  const Scalar& value);
197 
198 template <
199  template <typename, int, int, int, int, int> class _Matrix,
200  typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols,
201  typename Scalar
202 >
203 inline
204 void
205 constant_fill(_Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows,
206  _MaxCols>& output,
207  const Scalar& value);
208 
209 
210 template <
211  template <typename, int, int, int, int, int> class _Matrix,
212  typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols
213 >
214 inline
215 void
216 set_zero(_Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& a);
217 
218 /*
219 template <template <typename, int, int, int, int, int> class _Matrix,
220  typename T, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols,
221  typename VectorScalar
222 >
223 inline
224 _Matrix<T,_Rows,_Cols,_Options,_MaxRows,_MaxCols>
225  custom_clone(const _Matrix<T,_Rows,_Cols,_Options,_MaxRows,_MaxCols> & example, const VectorScalar& values, const _Matrix<unsigned int,_Rows,_Cols,_Options,_MaxRows,_MaxCols> & indexes);
226 */
227 
228 template <typename Condition, typename T1, typename T2>
229 inline
230 typename enable_if_c<
231  is_eigen<T1>::value &&
232  is_eigen<T2>::value,
233  typename state_type<T1>::type
234 >::type
235 if_else(
236 const Condition& condition,
237 const T1& if_true,
238 const T2& if_false);
239 
240 
241 template <typename VectorT,
242  template <typename, int, int, int, int, int> class _Matrix,
243  typename _UIntT, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols
244 >
245 inline
246 typename enable_if_c<
247  is_eigen<typename value_type<VectorT>::type>::value,
248  typename value_type<VectorT>::type
249 >::type
250 eval_index(const VectorT& vec, const _Matrix<_UIntT, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& index);
251 
252 template <typename T>
253 inline
254 bool conjunction_root(const T & vec, eigen_library_tag);
255 
256 template <typename T>
257 inline
258 bool disjunction_root(const T & vec, eigen_library_tag);
259 
260 } // end namespace Antioch
261 
262 #endif //ANTIOCH_EIGEN_UTILS_DECL_H
Antioch::enable_if_c< is_eigen< T >::value, typename value_type< T >::type >::type max(const T &in)
Definition: eigen_utils.h:88
#define ANTIOCH_RETURNEXPR(Type, Expr)
bool conjunction_root(const T &vec, eigen_library_tag)
Definition: eigen_utils.h:278
static const bool value
_Matrix< NewScalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > type
bool disjunction_root(const T &vec, eigen_library_tag)
Definition: eigen_utils.h:285
Antioch::enable_if_c< is_eigen< T >::value, typename value_type< T >::type >::type min(const T &in)
Definition: eigen_utils.h:98
enable_if_c< is_eigen< typename value_type< VectorT >::type >::value, typename value_type< VectorT >::type >::type eval_index(const VectorT &vec, const _Matrix< _UIntT, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &index)
Definition: eigen_utils.h:268
_Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > constant_clone(const _Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &ex, const Scalar &value)
Definition: eigen_utils.h:181
max(const _Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &a, const _Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &b) ANTIOCH_AUTOFUNC(_Matrix< _Scalar ANTIOCH_COMMA _Rows ANTIOCH_COMMA _Cols ANTIOCH_COMMA _Options ANTIOCH_COMMA _MaxRows ANTIOCH_COMMA _MaxCols >
enable_if_c< is_eigen< T1 >::value &&is_eigen< T2 >::value, typename state_type< T1 >::type >::type if_else(const Condition &condition, const T1 &if_true, const T2 &if_false)
Definition: eigen_utils.h:250
void set_zero(_Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &a)
Definition: eigen_utils.h:217
void constant_fill(_Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &output, const Scalar &value)
Definition: eigen_utils.h:204
The parameters are reduced parameters.
typename _Scalar int _Rows int _Cols int _Options int _MaxRows int _MaxCols inline min(const _Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &a, const _Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &b) ANTIOCH_AUTOFUNC(_Matrix< _Scalar ANTIOCH_COMMA _Rows ANTIOCH_COMMA _Cols ANTIOCH_COMMA _Options ANTIOCH_COMMA _MaxRows ANTIOCH_COMMA _MaxCols >
_Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > zero_clone(const _Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &ex)
Definition: eigen_utils.h:145
#define ANTIOCH_AUTO(Type)

Generated on Thu Jul 7 2016 11:09:46 for antioch-0.4.0 by  doxygen 1.8.8