fmatvec  0.0.0
Fast Matrix/Vector Library
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 fmatvec {
81 
82  /***** initialization types *****/
83 
84  class Noinit { };
85  class Init { };
86  class Eye { };
87 
88  static Noinit NONINIT = Noinit();
89  static Init INIT = Init();
90  static Eye EYE = Eye();
91 
92  /***** matrix/vector (sub) types *****/
93 
94  class Ref {
95  };
96 
97  class Var {
98  };
99 
100  template<int M> class Fixed {
101  };
102 
103 // class General {
104 // };
105 //
106 // class GeneralBand {
107 // };
108 //
109 // class Symmetric {
110 // };
111 //
112 // class Diagonal {
113 // };
114 //
115 // class Sparse {
116 // };
117 //
118 // /*!
119 // * \brief Basic shape class for matrices.
120 // *
121 // * Class BasicType is the basic shape type.
122 // * */
123 // template<class Shape, class Mem>
124 // class Type {
125 // };
126 
132  class General {
133  };
134 
140  class GeneralBand {
141  };
142 
148  class Symmetric {
149  };
150 
156  class Rotation {
157  };
158 
164  class Diagonal {
165  };
166 
172  class Sparse {
173  };
174 
181  class Square {
182  };
183 
184 // template<int M, int N>
185 // class GeneralFixed: public BasicType {
186 // };
187 //
188 // template<int M>
189 // class SymmetricFixed: public BasicType {
190 // };
191 //
192 // class GeneralVar: public BasicType {
193 // };
194 //
195 // class SymmetricVar: public BasicType {
196 // };
197 //
198 // template<int M>
199 // class GeneralFixedVar: public BasicType {
200 // };
201 //
202 // template<int N>
203 // class GeneralVarFixed: public BasicType {
204 // };
205 
206  template<class AT1, class AT2> struct OperatorResult;
207 
208  #define FMATVEC_OPERATORRESULT1(AT, ATRes) \
209  template<> struct OperatorResult<AT, AT> { typedef ATRes Type; };
210 
211  #define FMATVEC_OPERATORRESULT2(AT1, AT2, ATRes) \
212  template<> struct OperatorResult<AT1, AT2> { typedef ATRes Type; }; \
213  template<> struct OperatorResult<AT2, AT1> { typedef ATRes Type; };
214 
215  FMATVEC_OPERATORRESULT1(double, double)
216  FMATVEC_OPERATORRESULT1(int, int)
217  FMATVEC_OPERATORRESULT1(std::complex<double>, std::complex<double>)
218 
219  FMATVEC_OPERATORRESULT2(double, std::complex<double>, std::complex<double>)
220  FMATVEC_OPERATORRESULT2(int, std::complex<double>, std::complex<double>)
221  FMATVEC_OPERATORRESULT2(int, double, double)
222 
223  // FMATVEC_ASSERT(expr, AT) is fully equal to assert(expr) if no spezialization of AssertUseException for AT exists.
224  // FMATVEC_ASSERT(expr, AT) is similar to assert(expr) but throws an exception instead of calling abort regardless whether
225  // NDEBUG is defined or not if their is a spezialization of AssertUseException for AT with value = true
226  #define FMATVEC_ASSERT(expr, AT) fmatvec_assert<AssertUseException<AT>::value>(expr, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, #expr);
227 
228  // a template which defined if for AT exceptions or assert should be used in fmatvec.
229  // spezialize this template to use exceptions.
230  // see also ast.h for a spezialization.
231  template<typename AT> struct AssertUseException { constexpr static bool value = false; };
232 
233  template<bool value>
234  inline void fmatvec_assert(bool expr, std::string_view file, int line, std::string_view func, std::string_view exprStr);
235 
236  template<>
237  inline void fmatvec_assert<false>(bool expr, std::string_view file, int line, std::string_view func, std::string_view exprStr) {
238  #ifndef NDEBUG
239  if(!expr) {
240  // print with fprintf since printing with higher level functions like cerr may be redirected.
241  fprintf(stderr, (std::string(file)+":"+std::to_string(line)+": "+
242  std::string(func)+": Assertion `"+std::string(exprStr)+"' failed.").c_str());
243  std::abort();
244  }
245  #endif
246  }
247 
248  template<>
249  inline void fmatvec_assert<true>(bool expr, std::string_view file, int line, std::string_view func, std::string_view exprStr) {
250  if(!expr)
251  throw std::runtime_error(std::string(file)+":"+std::to_string(line)+": "+
252  std::string(func)+": Assertion `"+std::string(exprStr)+"' failed.");
253  }
254 
255  class ErrorType;
256  template<class, class> class Vector;
257  template<class, class> class RowVector;
258  template<class, class, class, class> class Matrix;
259  template<class, class> class SquareMatrix;
260 
261  // Replace in a fmatvec scalar, vector or matrix the AT with ATNew.
262  template<class MatVec, class NewAT>
263  struct ReplaceAT;
264 
265  template<class NewAT>
266  struct ReplaceAT<ErrorType, NewAT> {
267  using Type = ErrorType;
268  };
269 
270  template<class NewAT>
271  struct ReplaceAT<double, NewAT> {
272  using Type = NewAT;
273  };
274 
275  template<class Shape, class OldAT, class NewAT>
276  struct ReplaceAT<Vector<Shape, OldAT>, NewAT> {
277  using Type = Vector<Shape, NewAT>;
278  };
279 
280  template<class Shape, class OldAT, class NewAT>
281  struct ReplaceAT<RowVector<Shape, OldAT>, NewAT> {
283  };
284 
285  template<class MatType, class RowShape, class ColShape, class OldAT, class NewAT>
286  struct ReplaceAT<Matrix<MatType, RowShape, ColShape, OldAT>, NewAT> {
288  };
289 
290  template<class Shape, class OldAT, class NewAT>
291  struct ReplaceAT<SquareMatrix<Shape, OldAT>, NewAT> {
293  };
294 
295 }
296 
297 #endif
Definition: fmatvec.h:38
This is the basic matrix class for arbitrary matrices.
Definition: fmatvec.h:41
Shape class for symmetric matrices.
Definition: types.h:148
Definition: types.h:85
Definition: types.h:97
Dummy shape class for square matrices.
Definition: types.h:181
Definition: fmatvec.h:50
Shape class for rotation matrices.
Definition: types.h:156
Definition: function.h:13
Shape class for general band matrices.
Definition: types.h:140
Definition: types.h:94
Definition: fmatvec.h:44
Definition: fmatvec.h:47
Definition: types.h:231
Namespace fmatvec.
Definition: _memory.cc:28
Shape class for diagonal matrices.
Definition: types.h:164
Shape class for sparse matrices.
Definition: types.h:172
Definition: types.h:84
Definition: types.h:206
Basic shape class for matrices.
Definition: types.h:132
Definition: types.h:263
Definition: types.h:86