All Classes Namespaces Functions Typedefs Enumerations Pages
fixed_symmetric_matrix.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 fixed_symmetric_matrix_h
23 #define fixed_symmetric_matrix_h
24 
25 #include "types.h"
26 
27 namespace fmatvec {
28 
37  template <int M, class AT> class Matrix<Symmetric,Fixed<M>,Fixed<M>,AT> {
38 
39  protected:
40 
42 
43  AT ele[M][M];
44 
45  template <class Type, class Row, class Col> inline void deepCopy(const Matrix<Type,Row,Col,AT> &A);
46  template <class Row> inline void deepCopy(const Matrix<Symmetric,Row,Row,AT> &A);
47 
49 
50  public:
51 
52 // template<class Ini=All<AT> >
53 // Matrix(Ini ini=All<AT>()) {
54 // init(ini);
55 // }
56 // template<class Ini=All<AT> >
57 // Matrix(int m_, int n_, Ini ini=All<AT>()) {
58 // init(ini);
59 // }
60 
61  Matrix(Noinit ini) { }
62  Matrix(Init ini=INIT, const AT &a=0) { init(a); }
63  Matrix(Eye ini, const AT &a=1) { init(ini,a); }
64  Matrix(int m, int n, Noinit ini) { }
65  Matrix(int m, int n, Init ini, const AT &a=0) { init(a); }
66  Matrix(int m, int n, Eye ini, const AT &a=1) { init(ini,a); }
67 
68  explicit Matrix(const Matrix<General,Fixed<M>,Fixed<M>,AT>& A) {
69  deepCopy(A);
70  }
71 
72  template<class Row>
74 
75 #ifndef FMATVEC_NO_SIZE_CHECK
76  assert(A.size() == M);
77 #endif
78 
79  deepCopy(A);
80  }
81 
82  template<class Type, class Row, class Col>
83  explicit Matrix(const Matrix<Type,Row,Col,AT> &A) {
84 
85 #ifndef FMATVEC_NO_SIZE_CHECK
86  assert(A.rows() == M);
87  assert(A.cols() == M);
88 #endif
89 
90  deepCopy(A);
91  }
92 
104  AT& operator()(int i, int j) {
105 #ifndef FMATVEC_NO_BOUNDS_CHECK
106  assert(i>=0);
107  assert(j>=0);
108  assert(i<M);
109  assert(j<M);
110 #endif
111 
112  return e(i,j);
113  };
114 
119  const AT& operator()(int i, int j) const {
120 #ifndef FMATVEC_NO_BOUNDS_CHECK
121  assert(i>=0);
122  assert(j>=0);
123  assert(i<M);
124  assert(j<M);
125 #endif
126 
127  return e(i,j);
128  };
129 
130  AT& ei(int i, int j) {
131  return ele[i][j];
132  };
133 
134  const AT& ei(int i, int j) const {
135  return ele[i][j];
136  };
137 
138  AT& ej(int i, int j) {
139  return ele[j][i];
140  };
141 
142  const AT& ej(int i, int j) const {
143  return ele[j][i];
144  };
145 
146  AT& e(int i, int j) {
147  return j > i ? ej(i,j) : ei(i,j);
148  };
149 
150  const AT& e(int i, int j) const {
151  return j > i ? ej(i,j) : ei(i,j);
152  };
153 
159  AT* operator()() {return ele;};
160 
165  const AT* operator()() const {return ele;};
166 
171  int size() const {return M;};
172 
177  int rows() const {return M;};
178 
183  int cols() const {return M;};
184 
189  int ldim() const {return M;};
190 
198  const CBLAS_ORDER blasOrder() const {
199  return CblasColMajor;
200  };
201 
209  const CBLAS_UPLO blasUplo() const {
210  return CblasLower;
211  };
212 
220  inline Matrix<Symmetric,Fixed<M>,Fixed<M>,AT>& init(const AT &a=0);
221  inline Matrix<Symmetric,Fixed<M>,Fixed<M>,AT>& init(Init, const AT &a=0) { return init(a); }
222  inline Matrix<Symmetric,Fixed<M>,Fixed<M>,AT>& init(Eye, const AT &a=1);
223  inline Matrix<Symmetric,Fixed<M>,Fixed<M>,AT>& init(Noinit, const AT &a=0) { return *this; }
224 
229  inline operator std::vector<std::vector<AT> >();
230  };
231 
232  template <int M, class AT>
234 
235  for(int i=0; i<M; i++)
236  for(int j=i; j<M; j++)
237  ej(i,j) = val;
238 
239  return *this;
240  }
241 
242  template <int M, class AT>
243  inline Matrix<Symmetric,Fixed<M>,Fixed<M>,AT>& Matrix<Symmetric,Fixed<M>,Fixed<M>,AT>::init(Eye, const AT &val) {
244 
245  for(int i=0; i<size(); i++) {
246  ej(i,i) = val;
247  for(int j=i+1; j<size(); j++) {
248  ej(i,j) = 0;
249  }
250  }
251  return *this;
252  }
253 
254  template <int M, class AT>
255  inline Matrix<Symmetric,Fixed<M>,Fixed<M>,AT>::operator std::vector<std::vector<AT> >() {
256  std::vector<std::vector<AT> > ret(rows());
257  for(int r=0; r<rows(); r++) {
258  ret[r].resize(cols());
259  for(int c=0; c<cols(); c++)
260  ret[r][c]=operator()(r,c);
261  }
262  return ret;
263  }
264 
266 
267  template <int M, class AT> template <class Type, class Row, class Col>
268  inline void Matrix<Symmetric,Fixed<M>,Fixed<M>,AT>::deepCopy(const Matrix<Type,Row,Col,AT> &A) {
269  for(int i=0; i<M; i++)
270  for(int j=i; j<M; j++)
271  ej(i,j) = A.e(i,j);
272  }
273 
274  template <int M, class AT> template <class Row>
275  inline void Matrix<Symmetric,Fixed<M>,Fixed<M>,AT>::deepCopy(const Matrix<Symmetric,Row,Row,AT> &A) {
276  for(int i=0; i<M; i++)
277  for(int j=i; j<M; j++)
278  ej(i,j) = A.ej(i,j);
279  }
280 
282 
283 }
284 
285 #endif
Definition: types.h:68
This is the basic matrix class for arbitrary matrices.
Definition: matrix.h:56
Shape class for symmetric matrices.
Definition: types.h:116
Definition: matrix.h:39
int rows() const
Number of rows.
Definition: fixed_symmetric_matrix.h:177
const CBLAS_UPLO blasUplo() const
Symmetry convention.
Definition: fixed_symmetric_matrix.h:209
int rows() const
Number of rows.
const AT * operator()() const
Pointer operator.
Definition: fixed_symmetric_matrix.h:165
const AT & operator()(int i, int j) const
Element operator.
Definition: fixed_symmetric_matrix.h:119
int cols() const
Number of columns.
const CBLAS_ORDER blasOrder() const
Storage convention.
Definition: fixed_symmetric_matrix.h:198
int ldim() const
Leading dimension.
Definition: fixed_symmetric_matrix.h:189
AT * operator()()
Pointer operator.
Definition: fixed_symmetric_matrix.h:159
Definition: matrix.h:38
int cols() const
Number of columns.
Definition: fixed_symmetric_matrix.h:183
Basic shape class for matrices.
Definition: types.h:100
int size() const
Size.
Definition: fixed_symmetric_matrix.h:171
AT & operator()(int i, int j)
Element operator.
Definition: fixed_symmetric_matrix.h:104
Definition: matrix.h:40

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML