22 #ifndef square_matrix_h
23 #define square_matrix_h
25 #include "general_matrix.h"
51 typedef AT AtomicType;
62 SquareMatrix(
int n,
int lda,
int tp, Memory<AT> memory,
const AT* ele) :
Matrix<General,Ref,Ref,AT>(n, n, lda, tp, memory, ele) {
79 SquareMatrix(
int m, Init ini=INIT,
const AT &a=0) : Matrix<General,Ref,Ref,AT>(m,m,ini,a) { }
80 SquareMatrix(
int m, Eye ini,
const AT &a=1) : Matrix<General,Ref,Ref,AT>(m,m,ini,a) { }
107 #ifndef FMATVEC_NO_SIZE_CHECK
112 template<
class Type,
class Row,
class Col>
116 SquareMatrix<Ref,AT>& resize() {
117 Matrix<General,Ref,Ref,AT>::resize();
121 SquareMatrix<Ref,AT>& resize(
int m, Noinit) {
122 Matrix<General,Ref,Ref,AT>::resize(m,m,Noinit());
126 SquareMatrix<Ref,AT>& resize(
int m, Init ini=INIT,
const AT &a=0) {
127 Matrix<General,Ref,Ref,AT>::resize(m,m,ini,a);
131 SquareMatrix<Ref,AT>& resize(
int m, Eye ini,
const AT &a=1) {
132 Matrix<General,Ref,Ref,AT>::resize(m,m,ini,a);
140 throw std::runtime_error(
"Cannot resize a square matrix with different dimensions for rows and columns.");
163 template<
class Type,
class Row,
class Col>
SquareMatrix<Ref,AT>& operator<<(const Matrix<Type,Row,Col,AT> &A) {
164 #ifndef FMATVEC_NO_SIZE_CHECK
165 assert(A.rows() == A.cols());
183 #ifndef FMATVEC_NO_SIZE_CHECK
209 inline operator std::vector<std::vector<AT> >();
215 const SquareMatrix<Ref,AT> T()
const {
216 return SquareMatrix<Ref,AT>(n, lda, tp?
false:
true, memory, ele);
231 std::vector<std::vector<AT> > ret(size());
233 for(
int r=0; r<size(); r++) {
234 ret[r].resize(size());
235 for(
int c=0; c<size(); c++)
236 ret[r][c]= this->et(r,c);
240 for(
int r=0; r<size(); r++) {
241 ret[r].resize(size());
242 for(
int c=0; c<size(); c++)
243 ret[r][c]= this->er(r,c);
This is the basic matrix class for arbitrary matrices.
Definition: fmatvec.h:41
SquareMatrix(int m, AT *ele)
Regular Constructor.
Definition: square_matrix.h:89
AT & operator()(int i, int j)
Standard constructor.
Definition: matrix.h:86
int rows() const
Number of rows.
Definition: general_matrix.h:272
SquareMatrix< Ref, AT > & operator=(const SquareMatrix< Ref, AT > &A)
Assignment operator.
Definition: square_matrix.h:152
void resize(int m, int n)
Definition: square_matrix.h:138
int size() const
Size.
Definition: square_matrix.h:194
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:171
SquareMatrix()
Standard constructor.
Definition: square_matrix.h:73
SquareMatrix(const Matrix< General, Ref, Ref, AT > &A)
Copy Constructor.
Definition: square_matrix.h:106
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:39
SquareMatrix(const SquareMatrix< Ref, AT > &A)
Copy Constructor.
Definition: square_matrix.h:100
SquareMatrix< Ref, AT > & operator>>(const SquareMatrix< Ref, AT > &A)
Reference operator.
Definition: square_matrix.h:177
This is an index class for creating submatrices.
Definition: range.h:44
int cols() const
Number of columns.
Definition: general_matrix.h:278