fmatvec  0.0.0
Fast Matrix/Vector Library
fixed_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 fixed_square_matrix_h
23 #define fixed_square_matrix_h
24 
25 #include "fixed_general_matrix.h"
26 
27 namespace fmatvec {
28 
38  template <int M, class AT> class SquareMatrix<Fixed<M>,AT> : public Matrix<General,Fixed<M>,Fixed<M>,AT> {
39 
40  public:
41  static constexpr bool isVector {false};
42  typedef AT value_type;
43  typedef Square shape_type;
44 
45 // template<class Ini=All<AT>>
46 // SquareMatrix(Ini ini=All<AT>()) : Matrix<General,Fixed<M>,Fixed<M>,AT>(ini) { }
47 // template<class Ini=All<AT>>
48 // SquareMatrix(int m, Ini ini=All<AT>()) : Matrix<General,Fixed<M>,Fixed<M>,AT>(ini) { }
49 
50  explicit SquareMatrix(Noinit ini) : Matrix<General,Fixed<M>,Fixed<M>,AT>(ini) { }
51  explicit SquareMatrix(Init ini=INIT, const AT &a=AT()) : Matrix<General,Fixed<M>,Fixed<M>,AT>(ini,a) { }
52  explicit SquareMatrix(Eye ini, const AT &a=1) : Matrix<General,Fixed<M>,Fixed<M>,AT>(ini,a) { }
53  explicit SquareMatrix(int m, Noinit ini) : Matrix<General,Fixed<M>,Fixed<M>,AT>(ini) { FMATVEC_ASSERT(m==M, AT); }
54  explicit SquareMatrix(int m, Init ini=INIT, const AT &a=AT()) : Matrix<General,Fixed<M>,Fixed<M>,AT>(ini,a) { FMATVEC_ASSERT(m==M, AT); }
55  explicit SquareMatrix(int m, Eye ini, const AT &a=1) : Matrix<General,Fixed<M>,Fixed<M>,AT>(ini,a) { FMATVEC_ASSERT(m==M, AT); }
56 
61  SquareMatrix(const SquareMatrix<Fixed<M>,AT> &A) = default;
62 
67  template<class Row>
69 
74  template<class Type, class Row, class Col>
75  explicit SquareMatrix(const Matrix<Type,Row,Col,AT>& A) : Matrix<General,Fixed<M>,Fixed<M>,AT>(A) { }
76 
77  SquareMatrix(const char *str) : Matrix<General,Fixed<M>,Fixed<M>,AT>(str) { }
78 
85  inline SquareMatrix<Fixed<M>,AT>& operator=(const SquareMatrix<Fixed<M>,AT> &A) = default;
86 
93  template <class Type, class Row, class Col>
95  Matrix<General,Fixed<M>,Fixed<M>,AT>::operator=(A);
96  return *this;
97  }
98 
105  template<class Type, class Row, class Col>
106  inline SquareMatrix<Fixed<M>,AT>& operator<<=(const Matrix<Type,Row,Col,AT> &A) { return operator=(A); }
107 
112  constexpr int size() const {return M;}
113  constexpr int rows() const {return M;}
114  constexpr int cols() const {return M;}
115 
116  using Matrix<General,Fixed<M>,Fixed<M>,AT>::operator();
117  using Matrix<General,Fixed<M>,Fixed<M>,AT>::e;
118 
123  explicit inline operator std::vector<std::vector<AT>>() const;
124 
125  inline const SquareMatrix<Fixed<M>,AT> T() const;
126  };
127 
128  template <int M, class AT>
129  inline const SquareMatrix<Fixed<M>,AT> SquareMatrix<Fixed<M>,AT>::T() const {
130  SquareMatrix<Fixed<M>,AT> A(NONINIT);
131  for(int i=0; i<M; i++)
132  for(int j=0; j<M; j++)
133  A.e(i,j) = e(j,i);
134  return A;
135  }
136 
137  template <int M, class AT>
138  inline SquareMatrix<Fixed<M>,AT>::operator std::vector<std::vector<AT>>() const {
139  std::vector<std::vector<AT>> ret(size());
140  for(int r=0; r<size(); r++) {
141  ret[r].resize(size());
142  for(int c=0; c<size(); c++)
143  ret[r][c]= e(r,c);
144  }
145  return ret;
146  }
147 
148 }
149 
150 #endif
Definition: fmatvec.h:38
SquareMatrix(const Matrix< Type, Row, Col, AT > &A)
Copy Constructor.
Definition: fixed_square_matrix.h:75
This is the basic matrix class for arbitrary matrices.
Definition: fmatvec.h:41
constexpr int size() const
Size.
Definition: fixed_square_matrix.h:112
Definition: types.h:85
SquareMatrix< Fixed< M >, AT > & operator=(const Matrix< Type, Row, Col, AT > &A)
Assignment operator.
Definition: fixed_square_matrix.h:94
Dummy shape class for square matrices.
Definition: types.h:181
SquareMatrix(const SquareMatrix< Row, AT > &A)
Copy Constructor.
Definition: fixed_square_matrix.h:68
Definition: fmatvec.h:44
Namespace fmatvec.
Definition: _memory.cc:28
Definition: types.h:84
Basic shape class for matrices.
Definition: types.h:132
Definition: types.h:86