SeldonHeader.hxx
1 // Copyright (C) 2001-2009 Vivien Mallet
2 //
3 // This file is part of the linear-algebra library Seldon,
4 // http://seldon.sourceforge.net/.
5 //
6 // Seldon is free software; you can redistribute it and/or modify it under the
7 // terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 2.1 of the License, or (at your option)
9 // any later version.
10 //
11 // Seldon is distributed in the hope that it will be useful, but WITHOUT ANY
12 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
14 // more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with Seldon. If not, see http://www.gnu.org/licenses/.
18 
19 
20 #ifndef SELDON_FILE_SELDONHEADER_HXX
21 
22 #include <iostream>
23 #include <algorithm>
24 #include <vector>
25 #include <complex>
26 #include <cstring>
27 #include <string>
28 #include <sstream>
29 #include <fstream>
30 #include <limits>
31 #include <cstdlib>
32 #include <ctime>
33 #include <exception>
34 #include <stdexcept>
35 
36 // For the compiled library.
37 #ifdef SELDON_WITH_COMPILED_LIBRARY
38 #define SELDON_EXTERN extern
39 #else
40 #define SELDON_EXTERN
41 #endif
42 
43 // For backward compatibility.
44 #ifdef SELDON_WITH_CBLAS
45 #define SELDON_WITH_BLAS
46 #endif
47 
48 // CBLAS enums are defined here to avoid SELDON_WITH_BLAS in MatrixFlag.hxx
49 // as a result, compiled version of Seldon is quick to switch from a Blas to a non-Blas version
50 extern "C"
51 {
52  enum CBLAS_ORDER {CblasRowMajor=101, CblasColMajor=102};
53  enum CBLAS_TRANSPOSE {CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113};
54  enum CBLAS_UPLO {CblasUpper=121, CblasLower=122};
55  enum CBLAS_DIAG {CblasNonUnit=131, CblasUnit=132};
56  enum CBLAS_SIDE {CblasLeft=141, CblasRight=142};
57 }
58 
59 #ifdef SELDON_WITH_BLAS
60 extern "C"
61 {
62 #include "computation/interfaces/cblas.h"
63 }
64 #endif
65 
67 // DEBUG LEVELS //
69 
70 #ifdef SELDON_DEBUG_LEVEL_4
71 #ifndef SELDON_DEBUG_LEVEL_3
72 #define SELDON_DEBUG_LEVEL_3
73 #endif
74 #endif
75 
76 #ifdef SELDON_DEBUG_LEVEL_3
77 #ifndef SELDON_CHECK_BOUNDS
78 #define SELDON_CHECK_BOUNDS
79 #endif
80 #ifndef SELDON_DEBUG_LEVEL_2
81 #define SELDON_DEBUG_LEVEL_2
82 #endif
83 #endif
84 
85 #ifdef SELDON_DEBUG_LEVEL_2
86 #ifndef SELDON_CHECK_DIMENSIONS
87 #define SELDON_CHECK_DIMENSIONS
88 #endif
89 #ifndef SELDON_DEBUG_LEVEL_1
90 #define SELDON_DEBUG_LEVEL_1
91 #endif
92 #endif
93 
94 #ifdef SELDON_DEBUG_LEVEL_1
95 #ifndef SELDON_LAPACK_CHECK_INFO
96 #define SELDON_LAPACK_CHECK_INFO
97 #endif
98 #ifndef SELDON_CHECK_MEMORY
99 #define SELDON_CHECK_MEMORY
100 #endif
101 #ifndef SELDON_CHECK_IO
102 #define SELDON_CHECK_IO
103 #endif
104 #ifndef SELDON_DEBUG_LEVEL_0
105 #define SELDON_DEBUG_LEVEL_0
106 #endif
107 #endif
108 
109 #ifdef SELDON_DEBUG_LEVEL_0
110 #ifndef SELDON_DEBUG_LEVEL_1
111 #ifndef SELDON_WITHOUT_THROW
112 #define SELDON_WITHOUT_THROW
113 #endif
114 #endif
115 #endif
116 
117 // Convenient macros to catch exceptions.
118 #ifndef TRY
119 #define TRY try {
120 #endif
121 #ifndef END
122 #define END \
123  } \
124  catch(Seldon::Error& Err) \
125  { \
126  Err.CoutWhat(); \
127  return 1; \
128  } \
129  catch (std::exception& Err) \
130  { \
131  std::cout << "C++ exception: " << Err.what() << std::endl; \
132  return 1; \
133  } \
134  catch (std::string& str) \
135  { \
136  std::cout << str << std::endl; \
137  return 1; \
138  } \
139  catch (const char* str) \
140  { \
141  std::cout << str << std::endl; \
142  return 1; \
143  } \
144  catch(...) \
145  { \
146  std::cout << "Unknown exception..." << std::endl; \
147  return 1; \
148  }
149 #endif
150 
152 #ifndef ERR
153 #define ERR(x) std::cout << "Hermes - " #x << std::endl
154 #endif
155 #ifndef DISP
157 #define DISP(x) std::cout << #x ": " << x << std::endl
158 #endif
159 #ifndef DISPLAY
161 #define DISPLAY(x) std::cout << #x ": " << x << std::endl
162 #endif
163 
164 // For backward compatibility. These lines should be removed one day.
165 #define Vect_Full VectFull
166 #define Vect_Sparse VectSparse
167 
169 namespace Seldon
170 {
171  using namespace std;
172 }
173 
174 // Exceptions and useful functions.
175 #include "share/Errors.hxx"
176 #include "share/Common.hxx"
177 
178 // Default allocator.
179 #ifndef SELDON_DEFAULT_ALLOCATOR
180 #define SELDON_DEFAULT_ALLOCATOR NewAlloc
181 #endif
182 // Memory management.
183 #include "share/Allocator.hxx"
184 #include "share/DefaultAllocator.hxx"
185 
186 // Storage type.
187 #include "share/Storage.hxx"
188 
189 #include "share/MatrixFlag.hxx"
190 
191 // Properties.
192 #include "share/Properties.hxx"
193 
194 
195 namespace Seldon
196 {
197 
198 
199  // Base structure for all vectors.
200  template <class T, class Allocator>
201  class Vector_Base;
202 
203  // Vector class - specialized for each used type.
204  template <class T, class Storage = VectFull,
205  class Allocator = typename
206  SeldonDefaultAllocator<Storage, T>::allocator >
207  class Vector;
208 
209  // Full vector.
210  template <class T, class Allocator>
211  class Vector<T, VectFull, Allocator>;
212 
213  // Sparse vector.
214  template <class T, class Allocator>
215  class Vector<T, VectSparse, Allocator>;
216 
217  // Vector collection.
218  template <class T, class Allocator>
219  class Vector<T, Collection, Allocator>;
220 
221  // Matrix class - specialized for each used type.
222  template <class T, class Prop = General,
223  class Storage = RowMajor,
224  class Allocator = typename
225  SeldonDefaultAllocator<Storage, T>::allocator >
226  class Matrix;
227 
228  // column-major matrix.
229  template <class T, class Prop, class Allocator>
230  class Matrix<T, Prop, ColMajor, Allocator>;
231 
232  // row-major matrix.
233  template <class T, class Prop, class Allocator>
234  class Matrix<T, Prop, RowMajor, Allocator>;
235 
236  // column-major symmetric packed matrix.
237  template <class T, class Prop, class Allocator>
238  class Matrix<T, Prop, ColSymPacked, Allocator>;
239 
240  // row-major symmetric packed matrix.
241  template <class T, class Prop, class Allocator>
242  class Matrix<T, Prop, RowSymPacked, Allocator>;
243 
244  // column-major upper-triangular packed matrix.
245  template <class T, class Prop, class Allocator>
246  class Matrix<T, Prop, ColUpTriangPacked, Allocator>;
247 
248  // column-major lower-triangular packed matrix.
249  template <class T, class Prop, class Allocator>
250  class Matrix<T, Prop, ColLoTriangPacked, Allocator>;
251 
252  // row-major upper-triangular packed matrix.
253  template <class T, class Prop, class Allocator>
254  class Matrix<T, Prop, RowUpTriangPacked, Allocator>;
255 
256  // row-major lower-triangular packed matrix.
257  template <class T, class Prop, class Allocator>
258  class Matrix<T, Prop, RowLoTriangPacked, Allocator>;
259 
260  // column-major sparse matrix.
261  template <class T, class Prop, class Allocator>
262  class Matrix<T, Prop, ColSparse, Allocator>;
263 
264  // row-major sparse matrix.
265  template <class T, class Prop, class Allocator>
266  class Matrix<T, Prop, RowSparse, Allocator>;
267 
268  // column-major symmetric sparse matrix.
269  template <class T, class Prop, class Allocator>
270  class Matrix<T, Prop, ColSymSparse, Allocator>;
271 
272  // row-major symmetric sparse matrix.
273  template <class T, class Prop, class Allocator>
274  class Matrix<T, Prop, RowSymSparse, Allocator>;
275 
276  // column-major sparse matrix.
277  template <class T, class Prop, class Allocator>
278  class Matrix<T, Prop, ArrayColSparse, Allocator>;
279 
280  // row-major sparse matrix.
281  template <class T, class Prop, class Allocator>
282  class Matrix<T, Prop, ArrayRowSparse, Allocator>;
283 
284  // column-major symmetric sparse matrix.
285  template <class T, class Prop, class Allocator>
286  class Matrix<T, Prop, ArrayColSymSparse, Allocator>;
287 
288  // row-major symmetric sparse matrix.
289  template <class T, class Prop, class Allocator>
290  class Matrix<T, Prop, ArrayRowSymSparse, Allocator>;
291 
292  // 3D array.
293  template <class T, int N, class Allocator
295  class Array;
296 
297  // 3D array.
298  template <class T, class Allocator
300  class Array3D;
301 
302  // 4D array.
303  template <class T, class Allocator
305  class Array4D;
306 
307 
308 } // namespace Seldon.
309 
310 
311 const int ARRAY_MINRANK = 3;
312 const int ARRAY_MAXRANK = 9;
313 
314 #include "array/Array3D.hxx"
315 #include "array/Array4D.hxx"
316 #include "array/Array.hxx"
317 #include "matrix/Matrix_Base.hxx"
318 #include "matrix/Matrix_Pointers.hxx"
319 #include "matrix/Matrix_Triangular.hxx"
320 #include "matrix/Matrix_Symmetric.hxx"
321 #include "matrix/Matrix_Hermitian.hxx"
322 #include "matrix_sparse/Matrix_Sparse.hxx"
323 #include "matrix_sparse/Matrix_SymSparse.hxx"
324 #include "matrix/Matrix_SymPacked.hxx"
325 #include "matrix/Matrix_HermPacked.hxx"
326 #include "matrix/Matrix_TriangPacked.hxx"
327 #include "vector/Vector.hxx"
328 #include "vector/SparseVector.hxx"
329 #include "vector/Functions_Arrays.hxx"
330 #include "matrix/Functions.hxx"
331 #include "matrix_sparse/IOMatrixMarket.hxx"
332 #include "matrix_sparse/Matrix_Conversions.hxx"
333 #include "computation/basic_functions/Functions_Vector.hxx"
334 #include "computation/basic_functions/Functions_MatVect.hxx"
335 #include "computation/basic_functions/Functions_Matrix.hxx"
336 #include "computation/basic_functions/Functions_Base.hxx"
337 
338 #include "matrix/SubMatrix_Base.hxx"
339 #include "matrix/SubMatrix.hxx"
340 
341 // Blas interface.
342 #ifdef SELDON_WITH_BLAS
343 
344 #include "computation/interfaces/Blas_1.hxx"
345 #include "computation/interfaces/Blas_2.hxx"
346 #include "computation/interfaces/Blas_3.hxx"
347 
348 #endif
349 
350 // Lapack interface.
351 #ifdef SELDON_WITH_LAPACK
352 
353 #undef LAPACK_INTEGER
354 #define LAPACK_INTEGER int
355 #undef LAPACK_REAL
356 #define LAPACK_REAL float
357 #undef LAPACK_DOUBLEREAL
358 #define LAPACK_DOUBLEREAL double
359 #undef LAPACK_COMPLEX
360 #define LAPACK_COMPLEX void
361 #undef LAPACK_DOUBLECOMPLEX
362 #define LAPACK_DOUBLECOMPLEX void
363 #undef LAPACK_LOGICAL
364 #define LAPACK_LOGICAL int
365 #undef LAPACK_L_FP
366 #define LAPACK_L_FP int*
367 #undef LAPACK_FTNLEN
368 #define LAPACK_FTNLEN int*
369 extern "C"
370 {
371 #include "computation/interfaces/clapack.h"
372 }
373 #ifdef SELDON_LAPACK_CHECK_INFO
374 #ifndef SELDON_CHECK_INFO
375 #define SELDON_CHECK_INFO(f, lf) info.Check(f, lf)
376 #endif
377 #else
378 #ifndef SELDON_CHECK_INFO
379 #define SELDON_CHECK_INFO(f, lf)
380 #endif
381 #endif
382 
383 #include "computation/interfaces/Lapack_LinearEquations.hxx"
384 #include "computation/interfaces/Lapack_LeastSquares.hxx"
385 #include "computation/interfaces/Lapack_Eigenvalues.hxx"
386 
387 #endif // SELDON_WITH_LAPACK.
388 
389 #ifdef SELDON_WITH_MKL
390 #include "computation/interfaces/Mkl_Sparse.hxx"
391 #endif
392 
393 namespace Seldon
394 {
395 
396  typedef Array3D<int> IArr3D;
397  typedef Vector<int, VectFull> IVect;
398  typedef Vector<float, VectFull> SVect;
399  typedef Vector<double, VectFull> DVect;
400  typedef Vector<complex<float>, VectFull> CVect;
401  typedef Vector<complex<double>, VectFull> ZVect;
402 
403  typedef Matrix<int, General, ColMajor> IGCMat;
404  typedef Matrix<float, General, ColMajor> SGCMat;
405  typedef Matrix<double, General, ColMajor> DGCMat;
406  typedef Matrix<complex<float>, General, ColMajor> CGCMat;
407  typedef Matrix<complex<double>, General, ColMajor> ZGCMat;
408 
409  typedef Matrix<int, General, RowMajor> IGRMat;
410  typedef Matrix<float, General, RowMajor> SGRMat;
411  typedef Matrix<double, General, RowMajor> DGRMat;
412  typedef Matrix<complex<float>, General, RowMajor> CGRMat;
413  typedef Matrix<complex<double>, General, RowMajor> ZGRMat;
414 
415  typedef Matrix<int, General, RowSparse> IGRSMat;
416  typedef Matrix<float, General, RowSparse> SGRSMat;
417  typedef Matrix<double, General, RowSparse> DGRSMat;
418  typedef Matrix<complex<float>, General, RowSparse> CGRSMat;
419  typedef Matrix<complex<double>, General, RowSparse> ZGRSMat;
420 
421  typedef Matrix<int, General, ColSparse> IGCSMat;
422  typedef Matrix<float, General, ColSparse> SGCSMat;
423  typedef Matrix<double, General, ColSparse> DGCSMat;
424  typedef Matrix<complex<float>, General, ColSparse> CGCSMat;
425  typedef Matrix<complex<double>, General, ColSparse> ZGCSMat;
426 
427  // Vector class - specialized for each used type.
428  template <class T, class Storage, class Allocator>
429  class Vector
430  {
431  // Nothing in it: no default vector is supplied so as to avoid suprises!
432  };
433 
434 
435  // Matrix class - specialized for each used type.
436  template <class T, class Prop, class Storage, class Allocator>
437  class Matrix
438  {
439  // Nothing in it: no default matrix is supplied so as to avoid suprises!
440  };
441 
442 } // namespace Seldon.
443 
444 // small matrices and vectors
445 #include "vector/TinyVector.hxx"
446 #include "matrix/TinyMatrix.hxx"
447 
448 #define SELDON_FILE_SELDONHEADER_HXX
449 #endif
Seldon::RowMajor
Definition: Storage.hxx:45
Seldon::SeldonDefaultAllocator
Selection of default allocator depending on storage and value type.
Definition: Allocator.hxx:174
Seldon::ArrayColSparse
Definition: Storage.hxx:128
Seldon::ColSparse
Definition: Storage.hxx:79
Seldon::Vector
Definition: SeldonHeader.hxx:207
Seldon::Collection
Definition: StorageInline.cxx:84
Seldon::Array
Multi-dimensional Array.
Definition: Array.hxx:33
Seldon::Matrix
Definition: SeldonHeader.hxx:226
Seldon::ArrayRowSymSparse
Definition: Storage.hxx:132
Seldon::VectFull
Definition: StorageInline.cxx:74
Seldon::RowSymPacked
Definition: Storage.hxx:157
Seldon::ArrayColSymSparse
Definition: Storage.hxx:136
Seldon::Vector_Base
Base structure for all vectors.
Definition: SeldonHeader.hxx:201
Seldon::ColSymSparse
Definition: Storage.hxx:103
Seldon::RowUpTriangPacked
Definition: Storage.hxx:318
Seldon::ColSymPacked
Definition: Storage.hxx:146
Seldon::General
Definition: Properties.hxx:26
Seldon::ColUpTriangPacked
Definition: Storage.hxx:294
Seldon::RowSymSparse
Definition: Storage.hxx:114
Seldon::VectSparse
Definition: StorageInline.cxx:79
Seldon::RowLoTriangPacked
Definition: Storage.hxx:330
Seldon::Array3D
3D array.
Definition: Array3D.hxx:38
Seldon::Array4D
4D array.
Definition: Array4D.hxx:39
Seldon::ArrayRowSparse
Definition: Storage.hxx:124
Seldon::RowSparse
Definition: Storage.hxx:91
Seldon
Seldon namespace.
Definition: Array.cxx:24
Seldon::ColLoTriangPacked
Definition: Storage.hxx:306
Seldon::ColMajor
Definition: Storage.hxx:33