00001 #ifndef INDII_ML_AUX_MATRIX_HPP
00002 #define INDII_ML_AUX_MATRIX_HPP
00003
00004 #include "vector.hpp"
00005
00006 #include "boost/numeric/ublas/matrix.hpp"
00007 #include "boost/numeric/ublas/matrix_sparse.hpp"
00008 #include "boost/numeric/ublas/matrix_proxy.hpp"
00009 #include "boost/numeric/ublas/symmetric.hpp"
00010 #include "boost/numeric/ublas/triangular.hpp"
00011 #include "boost/numeric/ublas/banded.hpp"
00012 #include "boost/numeric/ublas/io.hpp"
00013 #include "boost/numeric/ublas/storage.hpp"
00014
00015 namespace indii {
00016 namespace ml {
00017 namespace aux {
00018
00019
00020
00021
00022 typedef boost::numeric::ublas::matrix<double,
00023 boost::numeric::ublas::column_major,
00024 boost::numeric::ublas::unbounded_array<double> > matrix;
00025
00026
00027
00028
00029 typedef boost::numeric::ublas::symmetric_matrix<double,
00030 boost::numeric::ublas::lower, boost::numeric::ublas::column_major,
00031 boost::numeric::ublas::unbounded_array<double> > symmetric_matrix;
00032
00033
00034
00035
00036 typedef boost::numeric::ublas::triangular_matrix<double,
00037 boost::numeric::ublas::lower, boost::numeric::ublas::column_major,
00038 boost::numeric::ublas::unbounded_array<double> >
00039 lower_triangular_matrix;
00040
00041
00042
00043
00044 typedef boost::numeric::ublas::triangular_matrix<double,
00045 boost::numeric::ublas::upper, boost::numeric::ublas::column_major,
00046 boost::numeric::ublas::unbounded_array<double> >
00047 upper_triangular_matrix;
00048
00049
00050
00051
00052 typedef boost::numeric::ublas::identity_matrix<double> identity_matrix;
00053
00054
00055
00056
00057 typedef boost::numeric::ublas::zero_matrix<double> zero_matrix;
00058
00059
00060
00061
00062 typedef boost::numeric::ublas::scalar_matrix<double> scalar_matrix;
00063
00064
00065
00066
00067 typedef boost::numeric::ublas::banded_matrix<double,
00068 boost::numeric::ublas::column_major,
00069 boost::numeric::ublas::unbounded_array<double> > banded_matrix;
00070
00071
00072
00073
00074 typedef boost::numeric::ublas::mapped_matrix<double,
00075 boost::numeric::ublas::column_major> sparse_matrix;
00076
00077
00078
00079
00080
00081
00082
00083
00084 typedef boost::numeric::ublas::mapped_matrix<short int,
00085 boost::numeric::ublas::column_major> projection_matrix;
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 void inv(matrix& A, matrix& AI);
00096
00097
00098
00099
00100
00101
00102 template <class T>
00103 boost::numeric::ublas::matrix_vector_range<T> diag(T& A);
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 template <class VT, class MT>
00115 void vectorToMatrix(const VT& x, MT& A);
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 template <class MT, class VT>
00127 void matrixToVector(const MT& A, VT& x);
00128
00129 }
00130 }
00131 }
00132
00133 template <class T>
00134 boost::numeric::ublas::matrix_vector_range<T> indii::ml::aux::diag(T& A) {
00135
00136 assert (A.size1() == A.size2());
00137
00138 const boost::numeric::ublas::range step(0, A.size1());
00139
00140 return boost::numeric::ublas::matrix_vector_range<T>(A, step, step);
00141 }
00142
00143 template <class VT, class MT>
00144 void indii::ml::aux::vectorToMatrix(const VT& x, MT& A) {
00145
00146 assert (x.size() == A.size1() * A.size2());
00147
00148 const unsigned int M = A.size1(), N = A.size2();
00149 unsigned int col;
00150 for (col = 0; col < N; col++) {
00151 column(A,col) = subrange(x, col*M, (col+1)*M);
00152 }
00153 }
00154
00155 template <class MT, class VT>
00156 void indii::ml::aux::matrixToVector(const MT& A, VT& x) {
00157
00158 assert (x.size() == A.size1() * A.size2());
00159
00160 const unsigned int M = A.size1(), N = A.size2();
00161 unsigned int col;
00162 for (col = 0; col < N; col++) {
00163 subrange(x, col*M, (col+1)*M) = column(A,col);
00164 }
00165 }
00166
00167 #endif
00168