Bayes++ Bayesian Filtering Classes  Release 2014.5 - Copyright (c) 2003,2004,2005,2006,2011,2012,2014 Michael Stevens
matSupSub.hpp
Go to the documentation of this file.
1 /*
2  * Bayes++ the Bayesian Filtering Library
3  * Copyright (c) 2002 Michael Stevens
4  * See accompanying Bayes++.htm for terms and conditions of use.
5  *
6  * $Id$
7  */
8 
9 /*
10  * Matrix types for filter classes
11  * Provides the predefined type 'Vec' and a variety of 'Matrix' types
12  * Replace this header to substitute alternative matrix support
13  *
14  * Everything in namespace Bayes_filter_matrix is intended to support the matrix storage
15  * and algebra requirements of the library. Therefore the interfaces and implementation is
16  * not intended to be stable.
17  */
18 
19 /*
20  * Use the Boost uBLAS Basic Linear Algebra library
21  * That is boost::numeric::ublas
22  * Thanks to Joerg Walter and Mathias Koch for an excellent library!
23  *
24  * Gappy matrix support: The macros BAYES_FILTER_(SPARSE/COMPRESSED/COORDINATE) control experimental gappy matrix support
25  * When enabled the default storage types are replaced with their sparse equivalents
26  */
27 
28 #include <boost/version.hpp>
29 #if !(BOOST_VERSION >= 103200)
30 #error Requires Boost 1.32.0 or later
31 #endif
32 
33 #include <boost/numeric/ublas/vector.hpp>
34 #include <boost/numeric/ublas/vector_proxy.hpp>
35 #include <boost/numeric/ublas/matrix.hpp>
36 #include <boost/numeric/ublas/matrix_proxy.hpp>
37 #include <boost/numeric/ublas/symmetric.hpp>
38 #include <boost/numeric/ublas/triangular.hpp>
39 #include <boost/numeric/ublas/banded.hpp>
40 #if defined(BAYES_FILTER_MAPPED) || defined(BAYES_FILTER_COMPRESSED) || defined(BAYES_FILTER_COORDINATE)
41 #include <map>
42 #include <boost/numeric/ublas/vector_sparse.hpp>
43 #include <boost/numeric/ublas/matrix_sparse.hpp>
44 #define BAYES_FILTER_GAPPY
45 #endif
46 
47 
48 
49 /* Filter Matrix Namespace */
50 namespace Bayesian_filter_matrix
51 {
52  // Allow use of a local ublas namespace
53 namespace ublas = boost::numeric::ublas;
54 
55 /*
56  * Declare the value used for ALL linear algebra operations
57  * Also required as the matrix/vector container value_type
58  */
59 typedef double Float;
60 
61 /*
62  * uBlas base types - these will be wrapper to provide the actual vector and matrix types
63  * Symmetric types don't appear. They are defined later by adapting these base types
64  */
65 namespace detail {
66  // Dense types
67 typedef ublas::vector<Float> BaseDenseVector;
68 typedef ublas::matrix<Float, ublas::row_major> BaseDenseRowMatrix;
69 typedef ublas::matrix<Float, ublas::column_major> BaseDenseColMatrix;
70 typedef ublas::triangular_matrix<Float, ublas::upper, ublas::row_major> BaseDenseUpperTriMatrix;
71 typedef ublas::triangular_matrix<Float, ublas::lower, ublas::row_major> BaseDenseLowerTriMatrix;
72 typedef ublas::banded_matrix<Float> BaseDenseDiagMatrix;
73  // Mapped types
74 #if defined(BAYES_FILTER_MAPPED)
75 typedef ublas::mapped_vector<Float, std::map<std::size_t,Float> > BaseSparseVector;
76 typedef ublas::mapped_matrix<Float, ublas::row_major, std::map<std::size_t,Float> > BaseSparseRowMatrix;
77 typedef ublas::mapped_matrix<Float, ublas::column_major, std::map<std::size_t,Float> > BaseSparseColMatrix;
78  // OR Compressed types
79 #elif defined(BAYES_FILTER_COMPRESSED)
80 typedef ublas::compressed_vector<Float> BaseSparseVector;
81 typedef ublas::compressed_matrix<Float, ublas::row_major> BaseSparseRowMatrix;
82 typedef ublas::compressed_matrix<Float, ublas::column_major> BaseSparseColMatrix;
83  // OR Coordinate types
84 #elif defined(BAYES_FILTER_COORDINATE)
85 typedef ublas::coordinate_vector<Float> BaseSparseVector;
86 typedef ublas::coordinate_matrix<Float, ublas::row_major> BaseSparseRowMatrix;
87 typedef ublas::coordinate_matrix<Float, ublas::column_major> BaseSparseColMatrix;
88 #endif
89 
90  // Default types Dense or Gappy
91 #ifndef BAYES_FILTER_GAPPY
92 typedef BaseDenseVector BaseVector;
93 typedef BaseDenseRowMatrix BaseRowMatrix;
94 typedef BaseDenseColMatrix BaseColMatrix;
95 typedef BaseDenseUpperTriMatrix BaseUpperTriMatrix;
96 typedef BaseDenseLowerTriMatrix BaseLowerTriMatrix;
97 typedef BaseDenseDiagMatrix BaseDiagMatrix;
98 #else
99 typedef BaseSparseVector BaseVector;
100 typedef BaseSparseRowMatrix BaseRowMatrix;
101 typedef BaseSparseColMatrix BaseColMatrix;
102 typedef BaseDenseUpperTriMatrix BaseUpperTriMatrix; // No sparse triangular or banded
103 typedef BaseDenseLowerTriMatrix BaseLowerTriMatrix;
104 typedef BaseDenseDiagMatrix BaseDiagMatrix;
105 #endif
106 
107 }
108 
109 }//namespace
110 
111 /*
112  * Common type independent uBlas interface
113  */
114 #include "uBLASmatrix.hpp"
BaseDenseRowMatrix BaseRowMatrix
Definition: matSupSub.hpp:93
ublas::triangular_matrix< Float, ublas::lower, ublas::row_major > BaseDenseLowerTriMatrix
Definition: matSupSub.hpp:71
ublas::triangular_matrix< Float, ublas::upper, ublas::row_major > BaseDenseUpperTriMatrix
Definition: matSupSub.hpp:70
double Float
Definition: matSupSub.hpp:59
ublas::matrix< Float, ublas::row_major > BaseDenseRowMatrix
Definition: matSupSub.hpp:68
BaseDenseUpperTriMatrix BaseUpperTriMatrix
Definition: matSupSub.hpp:95
BaseDenseDiagMatrix BaseDiagMatrix
Definition: matSupSub.hpp:97
ublas::matrix< Float, ublas::column_major > BaseDenseColMatrix
Definition: matSupSub.hpp:69
BaseDenseColMatrix BaseColMatrix
Definition: matSupSub.hpp:94
BaseDenseVector BaseVector
Definition: matSupSub.hpp:92
BaseDenseLowerTriMatrix BaseLowerTriMatrix
Definition: matSupSub.hpp:96
Definition: matSup.cpp:33
ublas::vector< Float > BaseDenseVector
Definition: matSupSub.hpp:67
ublas::banded_matrix< Float > BaseDenseDiagMatrix
Definition: matSupSub.hpp:72