fmatvec  2.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  typedef AT value_type;
42 
43 // template<class Ini=All<AT>>
44 // SquareMatrix(Ini ini=All<AT>()) : Matrix<General,Fixed<M>,Fixed<M>,AT>(ini) { }
45 // template<class Ini=All<AT>>
46 // SquareMatrix(int m, Ini ini=All<AT>()) : Matrix<General,Fixed<M>,Fixed<M>,AT>(ini) { }
47 
48  explicit SquareMatrix(Noinit ini) : Matrix<General,Fixed<M>,Fixed<M>,AT>(ini) { }
49  explicit SquareMatrix(Init ini=INIT, const AT &a=AT()) : Matrix<General,Fixed<M>,Fixed<M>,AT>(ini,a) { }
50  explicit SquareMatrix(Eye ini, const AT &a=1) : Matrix<General,Fixed<M>,Fixed<M>,AT>(ini,a) { }
51  explicit SquareMatrix(int m, Noinit ini) : Matrix<General,Fixed<M>,Fixed<M>,AT>(ini) { FMATVEC_ASSERT(m==M, AT); }
52  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); }
53  explicit SquareMatrix(int m, Eye ini, const AT &a=1) : Matrix<General,Fixed<M>,Fixed<M>,AT>(ini,a) { FMATVEC_ASSERT(m==M, AT); }
54 
59  SquareMatrix(const SquareMatrix<Fixed<M>,AT> &A) = default;
60 
65  template<class Row>
67 
72  template<class Type, class Row, class Col>
73  explicit SquareMatrix(const Matrix<Type,Row,Col,AT>& A) : Matrix<General,Fixed<M>,Fixed<M>,AT>(A) { }
74 
75  SquareMatrix(const char *str) : Matrix<General,Fixed<M>,Fixed<M>,AT>(str) { }
76 
83  inline SquareMatrix<Fixed<M>,AT>& operator=(const SquareMatrix<Fixed<M>,AT> &A) = default;
84 
91  template <class Type, class Row, class Col>
93  Matrix<General,Fixed<M>,Fixed<M>,AT>::operator=(A);
94  return *this;
95  }
96 
103  template<class Type, class Row, class Col>
104  inline SquareMatrix<Fixed<M>,AT>& operator<<=(const Matrix<Type,Row,Col,AT> &A) { return operator=(A); }
105 
110  int size() const {return M;}
111 
112  using Matrix<General,Fixed<M>,Fixed<M>,AT>::operator();
113  using Matrix<General,Fixed<M>,Fixed<M>,AT>::e;
114 
119  explicit inline operator std::vector<std::vector<AT>>() const;
120 
121  inline const SquareMatrix<Fixed<M>,AT> T() const;
122  };
123 
124  template <int M, class AT>
125  inline const SquareMatrix<Fixed<M>,AT> SquareMatrix<Fixed<M>,AT>::T() const {
126  SquareMatrix<Fixed<M>,AT> A(NONINIT);
127  for(int i=0; i<M; i++)
128  for(int j=0; j<M; j++)
129  A.e(i,j) = e(j,i);
130  return A;
131  }
132 
133  template <int M, class AT>
134  inline SquareMatrix<Fixed<M>,AT>::operator std::vector<std::vector<AT>>() const {
135  std::vector<std::vector<AT>> ret(size());
136  for(int r=0; r<size(); r++) {
137  ret[r].resize(size());
138  for(int c=0; c<size(); c++)
139  ret[r][c]= e(r,c);
140  }
141  return ret;
142  }
143 
144 }
145 
146 #endif
Definition: fmatvec.h:38
SquareMatrix(const Matrix< Type, Row, Col, AT > &A)
Copy Constructor.
Definition: fixed_square_matrix.h:73
This is the basic matrix class for arbitrary matrices.
Definition: fmatvec.h:41
Definition: types.h:85
SquareMatrix< Fixed< M >, AT > & operator=(const Matrix< Type, Row, Col, AT > &A)
Assignment operator.
Definition: fixed_square_matrix.h:92
SquareMatrix(const SquareMatrix< Row, AT > &A)
Copy Constructor.
Definition: fixed_square_matrix.h:66
Definition: fmatvec.h:44
Namespace fmatvec.
Definition: _memory.cc:28
int size() const
Size.
Definition: fixed_square_matrix.h:110
Definition: types.h:84
Basic shape class for matrices.
Definition: types.h:132
Definition: types.h:86