fmatvec  0.0.0
types.h
1 /* Copyright (C) 2003-2005 Martin Förg
2 
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16  *
17  * Contact:
18  * martin.o.foerg@googlemail.com
19  *
20  */
21 
22 #ifndef types_h
23 #define types_h
24 
25 #include <complex>
26 #include <string>
27 #include <stdexcept>
28 #include <boost/current_function.hpp>
29 
30 #ifdef _MSC_VER
31 #ifdef fmatvec_EXPORTS
32 #define FMATVEC_EXPORT __declspec(dllexport)
33 #else
34 #define FMATVEC_EXPORT __declspec(dllimport)
35 #endif
36 #else
37 #ifdef fmatvec_EXPORTS
38 #define FMATVEC_EXPORT __attribute((visibility ("default")))
39 #else
40 #define FMATVEC_EXPORT
41 #endif
42 #endif
43 
44 
45 #ifndef HAVE_LIBMKL_INTEL_LP64
46 #ifndef CBLAS_ENUM_DEFINED_H
47  #define CBLAS_ENUM_DEFINED_H
48  enum CBLAS_ORDER {CblasRowMajor=101, CblasColMajor=102 };
49  enum CBLAS_TRANSPOSE {CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113,
50  AtlasConj=114};
51  enum CBLAS_UPLO {CblasUpper=121, CblasLower=122};
52  enum CBLAS_DIAG {CblasNonUnit=131, CblasUnit=132};
53  enum CBLAS_SIDE {CblasLeft=141, CblasRight=142};
54 #endif
55 #define CBLAS_INDEX int
56 
57 #ifndef ATLAS_ENUM_H
58  #define ATLAS_ENUM_H
59  #define ATLAS_ORDER CBLAS_ORDER
60  #define AtlasRowMajor CblasRowMajor
61  #define AtlasColMajor CblasColMajor
62  #define ATLAS_TRANS CBLAS_TRANSPOSE
63  #define AtlasNoTrans CblasNoTrans
64  #define AtlasTrans CblasTrans
65  #define AtlasConjTrans CblasConjTrans
66  #define ATLAS_UPLO CBLAS_UPLO
67  #define AtlasUpper CblasUpper
68  #define AtlasLower CblasLower
69  #define ATLAS_DIAG CBLAS_DIAG
70  #define AtlasNonUnit CblasNonUnit
71  #define AtlasUnit CblasUnit
72  #define ATLAS_SIDE CBLAS_SIDE
73  #define AtlasLeft CblasLeft
74  #define AtlasRight CblasRight
75 #endif
76 #else
77 #include "mkl_cblas.h"
78 #endif
79 
80 namespace std {
81  template<class T> class shared_ptr;
82 }
83 
84 namespace fmatvec {
85 
86  /***** initialization types *****/
87 
88  class Noinit { };
89  class Init { };
90  class Eye { };
91 
92  static Noinit NONINIT = Noinit();
93  static Init INIT = Init();
94  static Eye EYE = Eye();
95 
96  /***** matrix/vector (sub) types *****/
97 
98  class Ref {
99  };
100 
101  class Var {
102  };
103 
104  template<int M> class Fixed {
105  };
106 
112  class General {
113  };
114 
120  class GeneralBand {
121  };
122 
128  class Symmetric {
129  };
130 
136  class Rotation {
137  };
138 
144  class Diagonal {
145  };
146 
152  class Sparse {
153  };
154 
161  };
162 
169  class Square {
170  };
171 
172 // template<int M, int N>
173 // class GeneralFixed: public BasicType {
174 // };
175 //
176 // template<int M>
177 // class SymmetricFixed: public BasicType {
178 // };
179 //
180 // class GeneralVar: public BasicType {
181 // };
182 //
183 // class SymmetricVar: public BasicType {
184 // };
185 //
186 // template<int M>
187 // class GeneralFixedVar: public BasicType {
188 // };
189 //
190 // template<int N>
191 // class GeneralVarFixed: public BasicType {
192 // };
193 
194  template<class AT1, class AT2> struct OperatorResult;
195 
196  #define FMATVEC_OPERATORRESULT1(AT, ATRes) \
197  template<> struct OperatorResult<AT, AT> { typedef ATRes Type; };
198 
199  #define FMATVEC_OPERATORRESULT2(AT1, AT2, ATRes) \
200  template<> struct OperatorResult<AT1, AT2> { typedef ATRes Type; }; \
201  template<> struct OperatorResult<AT2, AT1> { typedef ATRes Type; };
202 
203  FMATVEC_OPERATORRESULT1(double, double)
204  FMATVEC_OPERATORRESULT1(int, int)
205  FMATVEC_OPERATORRESULT1(std::complex<double>, std::complex<double>)
206 
207  FMATVEC_OPERATORRESULT2(double, std::complex<double>, std::complex<double>)
208  FMATVEC_OPERATORRESULT2(int, std::complex<double>, std::complex<double>)
209  FMATVEC_OPERATORRESULT2(int, double, double)
210 
211  // FMATVEC_ASSERT(expr, AT) is fully equal to assert(expr) if no spezialization of AssertUseException for AT exists.
212  // FMATVEC_ASSERT(expr, AT) is similar to assert(expr) but throws an exception instead of calling abort regardless whether
213  // NDEBUG is defined or not if their is a spezialization of AssertUseException for AT with value = true
214  #define FMATVEC_ASSERT(expr, AT) fmatvec_assert<AssertUseException<AT>::value>(expr, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, #expr);
215 
216  // a template which defined if for AT exceptions or assert should be used in fmatvec.
217  // spezialize this template to use exceptions.
218  // see also ast.h for a spezialization.
219  template<typename AT> struct AssertUseException { constexpr static bool value = false; };
220 
221  template<bool value>
222  inline void fmatvec_assert(bool expr, std::string_view file, int line, std::string_view func, std::string_view exprStr);
223 
224  template<>
225  inline void fmatvec_assert<false>(bool expr, std::string_view file, int line, std::string_view func, std::string_view exprStr) {
226  #ifndef NDEBUG
227  if(!expr) {
228  // print with fprintf since printing with higher level functions like cerr may be redirected.
229  fprintf(stderr, "%s", (std::string(file)+":"+std::to_string(line)+": "+
230  std::string(func)+": Assertion `"+std::string(exprStr)+"' failed.").c_str());
231  std::abort();
232  }
233  #endif
234  }
235 
236  template<>
237  inline void fmatvec_assert<true>(bool expr, std::string_view file, int line, std::string_view func, std::string_view exprStr) {
238  if(!expr)
239  throw std::runtime_error(std::string(file)+":"+std::to_string(line)+": "+
240  std::string(func)+": Assertion `"+std::string(exprStr)+"' failed.");
241  }
242 
243  // tag dispatching
244  struct Transpose {};
245 
246  class ErrorType;
247  class SymbolicExpression;
248  template<class, class> class Vector;
249  template<class, class> class RowVector;
250  template<class, class, class, class> class Matrix;
251  template<class, class> class SquareMatrix;
252 
253  // Replace in a fmatvec scalar, vector or matrix the AT with ATNew.
254  template<class MatVec, class NewAT>
255  struct ReplaceAT;
256 
257  template<class NewAT>
258  struct ReplaceAT<ErrorType, NewAT> {
259  using Type = ErrorType;
260  };
261 
262  template<class NewAT>
263  struct ReplaceAT<double, NewAT> {
264  using Type = NewAT;
265  };
266 
267  template<class NewAT>
268  struct ReplaceAT<SymbolicExpression, NewAT> {
269  using Type = NewAT;
270  };
271 
272  template<class Shape, class OldAT, class NewAT>
273  struct ReplaceAT<Vector<Shape, OldAT>, NewAT> {
274  using Type = Vector<Shape, NewAT>;
275  };
276 
277  template<class Shape, class OldAT, class NewAT>
278  struct ReplaceAT<RowVector<Shape, OldAT>, NewAT> {
280  };
281 
282  template<class MatType, class RowShape, class ColShape, class OldAT, class NewAT>
283  struct ReplaceAT<Matrix<MatType, RowShape, ColShape, OldAT>, NewAT> {
285  };
286 
287  template<class Shape, class OldAT, class NewAT>
288  struct ReplaceAT<SquareMatrix<Shape, OldAT>, NewAT> {
290  };
291 
292 }
293 
294 #endif
Definition: fmatvec.h:39
Definition: types.h:244
This is the basic matrix class for arbitrary matrices.
Definition: fmatvec.h:42
Shape class for symmetric matrices.
Definition: types.h:128
Definition: types.h:89
Definition: types.h:101
Dummy shape class for square matrices.
Definition: types.h:169
Definition: fmatvec.h:51
Shape class for rotation matrices.
Definition: types.h:136
Definition: function.h:14
Shape class for general band matrices.
Definition: types.h:120
Shape class for sparse matrices.
Definition: types.h:160
Definition: types.h:98
Definition: types.h:81
Definition: fmatvec.h:45
Definition: fmatvec.h:48
Definition: types.h:219
Namespace fmatvec.
Definition: _memory.cc:28
Shape class for diagonal matrices.
Definition: types.h:144
Shape class for sparse matrices.
Definition: types.h:152
Definition: types.h:88
Definition: types.h:194
Shape class for general matrices.
Definition: types.h:112
Definition: types.h:255
Definition: ast.h:33
Definition: types.h:90