All Classes Namespaces Functions Variables Typedefs Enumerations Pages
var_square_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 var_square_matrix_h
23 #define var_square_matrix_h
24 
25 #include "fixed_general_matrix.h"
26 
27 namespace fmatvec {
28 
38  template <class AT> class SquareMatrix<Var,AT> : public Matrix<General,Var,Var,AT> {
39 
41 
42  public:
43 
44  typedef AT AtomicType;
45 
51 
52 // template<class Ini=All<AT> >
53 // SquareMatrix(int m, Ini ini=All<AT>()) : Matrix<General,Var,Var,AT>(m,m,ini) { }
54 
55  SquareMatrix(int m, Noinit ini) : Matrix<General,Var,Var,AT>(m,m,ini) { }
56  SquareMatrix(int m, Init ini=INIT, const AT &a=0) : Matrix<General,Var,Var,AT>(m,m,ini,a) { }
57  SquareMatrix(int m, Eye ini, const AT &a=1) : Matrix<General,Var,Var,AT>(m,m,ini,a) { }
58 
59  SquareMatrix(const char *str) : Matrix<General,Var,Var,AT>(str) { }
60 
65  template<class Type, class Row, class Col>
66  explicit SquareMatrix(const Matrix<Type,Row,Col,AT>& A) : Matrix<General,Var,Var,AT>(A) {
67  }
68 
69  template<class Row>
71  }
72 
73  SquareMatrix<Var,AT>& resize() {
74  Matrix<General,Var,Var,AT>::resize();
75  return *this;
76  }
77 
78  SquareMatrix<Var,AT>& resize(int m, Noinit) {
79  Matrix<General,Var,Var,AT>::resize(m,m,Noinit());
80  return *this;
81  }
82 
83  SquareMatrix<Var,AT>& resize(int m, Init ini=INIT, const AT &a=0) {
84  Matrix<General,Var,Var,AT>::resize(m,m,ini,a);
85  return *this;
86  }
87 
88  SquareMatrix<Var,AT>& resize(int m, Eye ini, const AT &a=1) {
89  Matrix<General,Var,Var,AT>::resize(m,m,ini,a);
90  return *this;
91  }
92 
94  bool transposed() {
95  return true;
96  }
97 
100  void resize(int m, int n) {
101  if(n!=m)
102  throw std::runtime_error("Cannot resize a square matrix with different dimensions for rows and columns.");
103  resize(m);
104  }
105 
112  template <class Type, class Row, class Col> SquareMatrix<Var,AT>& operator=(const Matrix<Type,Row,Col,AT> &A) {
114  return *this;
115  }
116 
121  int size() const {return M;};
122 
125 
130  inline operator std::vector<std::vector<AT> >();
131 
132  inline const SquareMatrix<Var,AT> T() const;
133 
134  };
135 
136  template <class AT>
137  inline const SquareMatrix<Var,AT> SquareMatrix<Var,AT>::T() const {
138  SquareMatrix<Var,AT> A(size(),NONINIT);
139  for(int i=0; i<M; i++)
140  for(int j=0; j<M; j++)
141  A.e(i,j) = e(j,i);
142  return A;
143  }
144 
145  template <class AT>
146  inline SquareMatrix<Var,AT>::operator std::vector<std::vector<AT> >() {
147  std::vector<std::vector<AT> > ret(size());
148  for(int r=0; r<size(); r++) {
149  ret[r].resize(size());
150  for(int c=0; c<size(); c++)
151  ret[r][c]= e(r,c);
152  }
153  return ret;
154  }
155 
156 }
157 
158 #endif
This is the basic matrix class for arbitrary matrices.
Definition: fmatvec.h:41
SquareMatrix(const Matrix< Type, Row, Col, AT > &A)
Copy Constructor.
Definition: var_square_matrix.h:66
Definition: types.h:65
SquareMatrix()
Standard constructor.
Definition: var_square_matrix.h:50
SquareMatrix< Var, AT > & operator=(const Matrix< Type, Row, Col, AT > &A)
Copy operator.
Definition: var_square_matrix.h:112
Definition: fmatvec.h:44
This is a matrix class of general quadratic matrices.
Definition: var_square_matrix.h:38
Definition: matrix.h:38
Basic shape class for matrices.
Definition: types.h:100
bool transposed()
The storage format of a var square matrix is c-storage order -&gt; return always true.
Definition: var_square_matrix.h:94
int size() const
Size.
Definition: var_square_matrix.h:121
void resize(int m, int n)
Definition: var_square_matrix.h:100

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML