fmatvec  2.0.0
Fast Matrix/Vector Library
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 value_type;
45 
50  explicit SquareMatrix() : Matrix<General,Var,Var,AT>() { }
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  explicit SquareMatrix(int m, Noinit ini) : Matrix<General,Var,Var,AT>(m,m,ini) { }
56  explicit SquareMatrix(int m, Init ini=INIT, const AT &a=AT()) : Matrix<General,Var,Var,AT>(m,m,ini,a) { }
57  explicit SquareMatrix(int m, Eye ini, const AT &a=1) : Matrix<General,Var,Var,AT>(m,m,ini,a) { }
58 
64  }
65 
70  template<class Row>
72  }
73 
78  template<class Type, class Row, class Col>
79  explicit SquareMatrix(const Matrix<Type,Row,Col,AT>& A) : Matrix<General,Var,Var,AT>(A) {
80  FMATVEC_ASSERT(A.rows() == A.cols(), AT);
81  }
82 
83  SquareMatrix(const char *str) : Matrix<General,Var,Var,AT>(str) { }
84 
85  SquareMatrix<Var,AT>& resize(int m, Noinit) {
86  Matrix<General,Var,Var,AT>::resize(m,m,Noinit());
87  return *this;
88  }
89 
90  SquareMatrix<Var,AT>& resize(int m, Init ini=INIT, const AT &a=AT()) {
91  Matrix<General,Var,Var,AT>::resize(m,m,ini,a);
92  return *this;
93  }
94 
95  SquareMatrix<Var,AT>& resize(int m, Eye ini, const AT &a=1) {
96  Matrix<General,Var,Var,AT>::resize(m,m,ini,a);
97  return *this;
98  }
99 
102  void resize(int m, int n) {
103  if(n!=m)
104  throw std::runtime_error("Cannot resize a square matrix with different dimensions for rows and columns.");
105  resize(m);
106  }
107 
116  return *this;
117  }
118 
125  template <class Type, class Row, class Col> SquareMatrix<Var,AT>& operator=(const Matrix<Type,Row,Col,AT> &A) {
127  return *this;
128  }
129 
136  template<class Type, class Row, class Col> SquareMatrix<Var,AT>& operator<<=(const Matrix<Type,Row,Col,AT> &A) {
137  FMATVEC_ASSERT(A.rows() == A.cols(), AT);
139  return *this;
140  }
141 
146  int size() const {return M;}
147 
150 
155  explicit inline operator std::vector<std::vector<AT>>() const;
156 
157  inline const SquareMatrix<Var,AT> T() const;
158  };
159 
160  template <class AT>
161  inline const SquareMatrix<Var,AT> SquareMatrix<Var,AT>::T() const {
162  SquareMatrix<Var,AT> A(size(),NONINIT);
163  for(int i=0; i<M; i++)
164  for(int j=0; j<M; j++)
165  A.e(i,j) = e(j,i);
166  return A;
167  }
168 
169  template <class AT>
170  inline SquareMatrix<Var,AT>::operator std::vector<std::vector<AT>>() const {
171  std::vector<std::vector<AT>> ret(size());
172  for(int r=0; r<size(); r++) {
173  ret[r].resize(size());
174  for(int c=0; c<size(); c++)
175  ret[r][c]= e(r,c);
176  }
177  return ret;
178  }
179 
180 }
181 
182 #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:79
Definition: types.h:97
SquareMatrix()
Standard constructor.
Definition: var_square_matrix.h:50
SquareMatrix< Var, AT > & operator=(const SquareMatrix< Var, AT > &A)
Assignment operator.
Definition: var_square_matrix.h:114
SquareMatrix(const SquareMatrix< Var, AT > &A)
Copy Constructor.
Definition: var_square_matrix.h:63
SquareMatrix< Var, AT > & operator=(const Matrix< Type, Row, Col, AT > &A)
Assignment operator.
Definition: var_square_matrix.h:125
Definition: fmatvec.h:44
SquareMatrix(const SquareMatrix< Row, AT > &A)
Copy Constructor.
Definition: var_square_matrix.h:71
This is a matrix class of general quadratic matrices.
Definition: var_square_matrix.h:38
int cols() const
Number of columns.
int size() const
Size.
Definition: var_square_matrix.h:146
Namespace fmatvec.
Definition: _memory.cc:28
Definition: types.h:84
Basic shape class for matrices.
Definition: types.h:132
int rows() const
Number of rows.
void resize(int m, int n)
Definition: var_square_matrix.h:102