fmatvec  2.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 
175 // template<int M, int N>
176 // class GeneralFixed: public BasicType {
177 // };
178 //
179 // template<int M>
180 // class SymmetricFixed: public BasicType {
181 // };
182 //
183 // class GeneralVar: public BasicType {
184 // };
185 //
186 // class SymmetricVar: public BasicType {
187 // };
188 //
189 // template<int M>
190 // class GeneralFixedVar: public BasicType {
191 // };
192 //
193 // template<int N>
194 // class GeneralVarFixed: public BasicType {
195 // };
196 
197  template<class AT1, class AT2> struct OperatorResult;
198 
199  #define FMATVEC_OPERATORRESULT1(AT, ATRes) \
200  template<> struct OperatorResult<AT, AT> { typedef ATRes Type; };
201 
202  #define FMATVEC_OPERATORRESULT2(AT1, AT2, ATRes) \
203  template<> struct OperatorResult<AT1, AT2> { typedef ATRes Type; }; \
204  template<> struct OperatorResult<AT2, AT1> { typedef ATRes Type; };
205 
206  FMATVEC_OPERATORRESULT1(double, double)
207  FMATVEC_OPERATORRESULT1(int, int)
208  FMATVEC_OPERATORRESULT1(std::complex<double>, std::complex<double>)
209 
210  FMATVEC_OPERATORRESULT2(double, std::complex<double>, std::complex<double>)
211  FMATVEC_OPERATORRESULT2(int, std::complex<double>, std::complex<double>)
212  FMATVEC_OPERATORRESULT2(int, double, double)
213 
214  // FMATVEC_ASSERT(expr, AT) is fully equal to assert(expr) if no spezialization of AssertUseException for AT exists.
215  // FMATVEC_ASSERT(expr, AT) is similar to assert(expr) but throws an exception instead of calling abort regardless whether
216  // NDEBUG is defined or not if their is a spezialization of AssertUseException for AT with value = true
217  #define FMATVEC_ASSERT(expr, AT) fmatvec_assert<AssertUseException<AT>::value>(expr, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, #expr);
218 
219  // a template which defined if for AT exceptions or assert should be used in fmatvec.
220  // spezialize this template to use exceptions.
221  // see mfmf for a spezialization.
222  template<typename AT> struct AssertUseException { constexpr static bool value = false; };
223 
224  template<bool value>
225  inline void fmatvec_assert(bool expr, std::string_view file, int line, std::string_view func, std::string_view exprStr);
226 
227  template<>
228  inline void fmatvec_assert<false>(bool expr, std::string_view file, int line, std::string_view func, std::string_view exprStr) {
229  #ifndef NDEBUG
230  if(!expr) {
231  // print with fprintf since printing with higher level functions like cerr may be redirected.
232  fprintf(stderr, (std::string(file)+":"+std::to_string(line)+": "+
233  std::string(func)+": Assertion `"+std::string(exprStr)+"' failed.").c_str());
234  std::abort();
235  }
236  #endif
237  }
238 
239  template<>
240  inline void fmatvec_assert<true>(bool expr, std::string_view file, int line, std::string_view func, std::string_view exprStr) {
241  if(!expr)
242  throw std::runtime_error(std::string(file)+":"+std::to_string(line)+": "+
243  std::string(func)+": Assertion `"+std::string(exprStr)+"' failed.");
244  }
245 
246 }
247 
248 #endif
Definition: fmatvec.h:38
Shape class for symmetric matrices.
Definition: types.h:148
Definition: types.h:85
Definition: types.h:97
Shape class for rotation matrices.
Definition: types.h:156
Shape class for general band matrices.
Definition: types.h:140
Definition: types.h:94
Definition: types.h:222
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:197
Basic shape class for matrices.
Definition: types.h:132
Definition: types.h:86