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 #define FMATVEC_MSVC_DISABLEW4251_BEGIN __pragma(warning(push)) __pragma(warning(disable:4251))
37 #define FMATVEC_MSVC_DISABLEW4251_END __pragma(warning(pop))
38#else
39 #ifdef fmatvec_EXPORTS
40 #define FMATVEC_EXPORT __attribute((visibility ("default")))
41 #else
42 #define FMATVEC_EXPORT
43 #endif
44 #define FMATVEC_MSVC_DISABLEW4251_BEGIN
45 #define FMATVEC_MSVC_DISABLEW4251_END
46#endif
47
48
49#ifndef HAVE_LIBMKL_INTEL_LP64
50#ifndef CBLAS_ENUM_DEFINED_H
51 #define CBLAS_ENUM_DEFINED_H
52 enum CBLAS_ORDER {CblasRowMajor=101, CblasColMajor=102 };
53 enum CBLAS_TRANSPOSE {CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113,
54 AtlasConj=114};
55 enum CBLAS_UPLO {CblasUpper=121, CblasLower=122};
56 enum CBLAS_DIAG {CblasNonUnit=131, CblasUnit=132};
57 enum CBLAS_SIDE {CblasLeft=141, CblasRight=142};
58#endif
59#define CBLAS_INDEX int
60
61#ifndef ATLAS_ENUM_H
62 #define ATLAS_ENUM_H
63 #define ATLAS_ORDER CBLAS_ORDER
64 #define AtlasRowMajor CblasRowMajor
65 #define AtlasColMajor CblasColMajor
66 #define ATLAS_TRANS CBLAS_TRANSPOSE
67 #define AtlasNoTrans CblasNoTrans
68 #define AtlasTrans CblasTrans
69 #define AtlasConjTrans CblasConjTrans
70 #define ATLAS_UPLO CBLAS_UPLO
71 #define AtlasUpper CblasUpper
72 #define AtlasLower CblasLower
73 #define ATLAS_DIAG CBLAS_DIAG
74 #define AtlasNonUnit CblasNonUnit
75 #define AtlasUnit CblasUnit
76 #define ATLAS_SIDE CBLAS_SIDE
77 #define AtlasLeft CblasLeft
78 #define AtlasRight CblasRight
79#endif
80#else
81#include "mkl_cblas.h"
82#endif
83
84namespace std {
85 template<class T> class shared_ptr;
86}
87
88namespace fmatvec {
89
90 /***** initialization types *****/
91
92 class Noinit { };
93 class Init { };
94 class Eye { };
95
96 static Noinit NONINIT = Noinit();
97 static Init INIT = Init();
98 static Eye EYE = Eye();
99
100 /***** matrix/vector (sub) types *****/
101
102 class Ref {
103 };
104
105 class Var {
106 };
107
108 template<int M> class Fixed {
109 };
110
116 class General {
117 };
118
125 };
126
132 class Symmetric {
133 };
134
140 class Rotation {
141 };
142
148 class Diagonal {
149 };
150
156 class Sparse {
157 };
158
165 };
166
173 class Square {
174 };
175
176// template<int M, int N>
177// class GeneralFixed: public BasicType {
178// };
179//
180// template<int M>
181// class SymmetricFixed: public BasicType {
182// };
183//
184// class GeneralVar: public BasicType {
185// };
186//
187// class SymmetricVar: public BasicType {
188// };
189//
190// template<int M>
191// class GeneralFixedVar: public BasicType {
192// };
193//
194// template<int N>
195// class GeneralVarFixed: public BasicType {
196// };
197
198 template<class AT1, class AT2> struct OperatorResult;
199
200 #define FMATVEC_OPERATORRESULT1(AT, ATRes) \
201 template<> struct OperatorResult<AT, AT> { typedef ATRes Type; };
202
203 #define FMATVEC_OPERATORRESULT2(AT1, AT2, ATRes) \
204 template<> struct OperatorResult<AT1, AT2> { typedef ATRes Type; }; \
205 template<> struct OperatorResult<AT2, AT1> { typedef ATRes Type; };
206
207 FMATVEC_OPERATORRESULT1(double, double)
208 FMATVEC_OPERATORRESULT1(float, float)
209 FMATVEC_OPERATORRESULT1(int, int)
210 FMATVEC_OPERATORRESULT1(std::complex<double>, std::complex<double>)
211 FMATVEC_OPERATORRESULT1(std::complex<float>, std::complex<float>)
212
213 FMATVEC_OPERATORRESULT2(double, std::complex<double>, std::complex<double>)
214 FMATVEC_OPERATORRESULT2(float, std::complex<float>, std::complex<float>)
215 FMATVEC_OPERATORRESULT2(double, std::complex<float>, std::complex<double>)
216 FMATVEC_OPERATORRESULT2(float, std::complex<double>, std::complex<double>)
217 FMATVEC_OPERATORRESULT2(int, std::complex<double>, std::complex<double>)
218 FMATVEC_OPERATORRESULT2(int, std::complex<float>, std::complex<float>)
219 FMATVEC_OPERATORRESULT2(int, double, double)
220 FMATVEC_OPERATORRESULT2(int, float, float)
221 FMATVEC_OPERATORRESULT2(float, 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, "%s", (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 // tag dispatching
256 struct Transpose {};
257
258 class ErrorType;
259 class SymbolicExpression;
260 template<class, class> class Vector;
261 template<class, class> class RowVector;
262 template<class, class, class, class> class Matrix;
263 template<class, class> class SquareMatrix;
264
265 // Replace in a fmatvec scalar, vector or matrix the AT with ATNew.
266 template<class MatVec, class NewAT>
267 struct ReplaceAT;
268
269 template<class NewAT>
270 struct ReplaceAT<ErrorType, NewAT> {
271 using Type = ErrorType;
272 };
273
274 template<class NewAT>
275 struct ReplaceAT<double, NewAT> {
276 using Type = NewAT;
277 };
278
279 template<class NewAT>
281 using Type = NewAT;
282 };
283
284 template<class Shape, class OldAT, class NewAT>
285 struct ReplaceAT<Vector<Shape, OldAT>, NewAT> {
287 };
288
289 template<class Shape, class OldAT, class NewAT>
290 struct ReplaceAT<RowVector<Shape, OldAT>, NewAT> {
292 };
293
294 template<class MatType, class RowShape, class ColShape, class OldAT, class NewAT>
295 struct ReplaceAT<Matrix<MatType, RowShape, ColShape, OldAT>, NewAT> {
297 };
298
299 template<class Shape, class OldAT, class NewAT>
300 struct ReplaceAT<SquareMatrix<Shape, OldAT>, NewAT> {
302 };
303
304 // Replace in a fmatvec scalar, vector or matrix the OldAT with NewAT.
305 template<class MatVec, class NewAT> // handles MatVec being a scalar
306 struct ReplaceAT {
307 using Type = NewAT;
308 };
309
310}
311
312#endif
Shape class for diagonal matrices.
Definition: types.h:148
Definition: function.h:14
Definition: types.h:94
Definition: types.h:108
Shape class for general band matrices.
Definition: types.h:124
Shape class for general matrices.
Definition: types.h:116
Definition: types.h:93
This is the basic matrix class for arbitrary matrices.
Definition: matrix.h:52
Definition: types.h:92
Definition: types.h:102
Shape class for rotation matrices.
Definition: types.h:140
Definition: matrix.h:170
Shape class for sparse matrices.
Definition: types.h:156
Definition: matrix.h:164
Dummy shape class for square matrices.
Definition: types.h:173
Definition: ast.h:38
Shape class for sparse matrices.
Definition: types.h:164
Shape class for symmetric matrices.
Definition: types.h:132
Definition: types.h:105
Definition: matrix.h:167
Definition: types.h:85
Namespace fmatvec.
Definition: _memory.cc:28
Definition: types.h:231
Definition: types.h:198
Definition: types.h:306
Definition: types.h:256