All Classes Namespaces Functions Typedefs Enumerations Pages
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 square_matrix_h
23 #define square_matrix_h
24 
25 #include "general_matrix.h"
26 
27 namespace fmatvec {
28 
38  template <class AT> class SquareMatrix<Ref,AT> : public Matrix<General,Ref,Ref,AT> {
39 
47 
48  public:
49 
51 
52  template <class T> friend SquareMatrix<Ref,T> trans(const SquareMatrix<Ref,T> &A);
53 
56 
57  protected:
58 
59  SquareMatrix(int n, int lda, int tp, Memory<AT> memory, const AT* ele) : Matrix<General,Ref,Ref,AT>(n, n, lda, tp, memory, ele) {
60  }
61 
63 
64  public:
65 
71 
72 // template<class Ini=All<AT> >
73 // SquareMatrix(int m, Ini ini=All<AT>()) : Matrix<General,Ref,Ref,AT>(m,m,ini) { }
74 
75  SquareMatrix(int m, Noinit ini) : Matrix<General,Ref,Ref,AT>(m,m,ini) { }
76  SquareMatrix(int m, Init ini=INIT, const AT &a=0) : Matrix<General,Ref,Ref,AT>(m,m,ini,a) { }
77  SquareMatrix(int m, Eye ini, const AT &a=1) : Matrix<General,Ref,Ref,AT>(m,m,ini,a) { }
78 
86  SquareMatrix(int m, AT* ele) : Matrix<General,Ref,Ref,AT>(m,m,ele) { }
87 
88  SquareMatrix(const char *str) : Matrix<General,Ref,Ref,AT>(str) { }
89 
98 
104 #ifndef FMATVEC_NO_SIZE_CHECK
105  assert(A.rows() == A.cols());
106 #endif
107  }
108 
109  template<class Type, class Row, class Col>
110  explicit SquareMatrix(const Matrix<Type,Row,Col,AT> &x) : Matrix<General,Ref,Ref,AT>(x) {
111  }
112 
113  SquareMatrix<Ref,AT>& resize() {
114  Matrix<General,Ref,Ref,AT>::resize();
115  return *this;
116  }
117 
118  SquareMatrix<Ref,AT>& resize(int m, Noinit) {
119  Matrix<General,Ref,Ref,AT>::resize(m,m,Noinit());
120  return *this;
121  }
122 
123  SquareMatrix<Ref,AT>& resize(int m, Init ini=INIT, const AT &a=0) {
124  Matrix<General,Ref,Ref,AT>::resize(m,m,ini,a);
125  return *this;
126  }
127 
128  SquareMatrix<Ref,AT>& resize(int m, Eye ini, const AT &a=1) {
129  Matrix<General,Ref,Ref,AT>::resize(m,m,ini,a);
130  return *this;
131  }
132 
143  return *this;
144  }
145 
152  template<class Type, class Row, class Col> SquareMatrix<Ref,AT>& operator<<(const Matrix<Type,Row,Col,AT> &A) {
153 #ifndef FMATVEC_NO_SIZE_CHECK
154  assert(A.rows() == A.cols());
155 #endif
157  return *this;
158  }
159 
168  return *this;
169  }
170 
172 #ifndef FMATVEC_NO_SIZE_CHECK
173  assert(A.rows() == A.cols());
174 #endif
176  return *this;
177  }
178 
183  int size() const {return m;};
184 
190  inline SquareMatrix<Ref,AT> copy() const;
191 
193 
198  inline operator std::vector<std::vector<AT> >();
199 
201  return SquareMatrix<Ref,AT>(n, lda, tp?false:true, memory, ele);
202  }
203 
204  const SquareMatrix<Ref,AT> T() const {
205  return SquareMatrix<Ref,AT>(n, lda, tp?false:true, memory, ele);
206  }
207  };
208 
209  template <class AT>
211 
212  SquareMatrix<Ref,AT> A(m,NONINIT);
213  A.deepCopy(*this);
214 
215  return A;
216  }
217 
218  template <class AT>
219  inline SquareMatrix<Ref,AT>::operator std::vector<std::vector<AT> >() {
220  std::vector<std::vector<AT> > ret(size());
221  if(tp) {
222  for(int r=0; r<size(); r++) {
223  ret[r].resize(size());
224  for(int c=0; c<size(); c++)
225  ret[r][c]= this->et(r,c);
226  }
227  }
228  else {
229  for(int r=0; r<size(); r++) {
230  ret[r].resize(size());
231  for(int c=0; c<size(); c++)
232  ret[r][c]= this->er(r,c);
233  }
234  }
235  return ret;
236  }
237 
238 }
239 
240 #endif
This is the basic matrix class for arbitrary matrices.
Definition: matrix.h:56
SquareMatrix(int m, AT *ele)
Regular Constructor.
Definition: square_matrix.h:86
AT & operator()(int i, int j)
Standard constructor.
Definition: matrix.h:85
int rows() const
Number of rows.
Definition: general_matrix.h:270
SquareMatrix< Ref, AT > & operator=(const SquareMatrix< Ref, AT > &A)
Assignment operator.
Definition: square_matrix.h:141
Definition: types.h:62
int size() const
Size.
Definition: square_matrix.h:183
Definition: matrix.h:212
This is a matrix class for general matrices.
Definition: general_matrix.h:40
std::istream & operator>>(std::istream &is, Matrix< Type, Row, Col, AT > &A)
Matrix input.
Definition: matrix.h:170
SquareMatrix()
Standard constructor.
Definition: square_matrix.h:70
SquareMatrix(const Matrix< General, Ref, Ref, AT > &A)
Copy Constructor.
Definition: square_matrix.h:103
This is an index class for creating submatrices.
Definition: index.h:34
Definition: matrix.h:38
RowVector< Ref, AT > trans(const Vector< Ref, AT > &x)
Transpose of a vector.
Definition: linear_algebra.h:1470
Basic shape class for matrices.
Definition: types.h:100
This is a matrix class of general quadratic matrices.
Definition: square_matrix.h:38
SquareMatrix(const SquareMatrix< Ref, AT > &A)
Copy Constructor.
Definition: square_matrix.h:97
SquareMatrix< Ref, AT > & operator>>(const SquareMatrix< Ref, AT > &A)
Reference operator.
Definition: square_matrix.h:166
int cols() const
Number of columns.
Definition: general_matrix.h:276

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML