22 #ifndef fixed_symmetric_matrix_h 23 #define fixed_symmetric_matrix_h 51 static constexpr
bool isVector {
false};
52 typedef AT value_type;
56 explicit Matrix(
Init ini=INIT,
const AT &a=AT()) { init(a); }
57 explicit Matrix(
Eye ini,
const AT &a=1) { init(ini,a); }
58 explicit Matrix(
int m,
int n,
Noinit ini) { FMATVEC_ASSERT(m==M && n==M, AT); }
59 explicit Matrix(
int m,
int n,
Init ini,
const AT &a=AT()) { FMATVEC_ASSERT(m==M && n==M, AT); init(a); }
60 explicit Matrix(
int m,
int n,
Eye ini,
const AT &a=1) { FMATVEC_ASSERT(m==M && n==M, AT); init(ini,a); }
76 FMATVEC_ASSERT(A.size() == M, AT);
85 template<
class Type,
class Row,
class Col>
87 FMATVEC_ASSERT(A.
rows() == M, AT);
88 FMATVEC_ASSERT(A.
cols() == M, AT);
106 template<
class Type,
class Row,
class Col>
108 FMATVEC_ASSERT(A.
rows() == A.
cols(), AT);
109 FMATVEC_ASSERT(M == A.
rows(), AT);
119 template<
class Type,
class Row,
class Col>
126 throw std::runtime_error(
"A fixed symmetric matrix cannot be resized.");
139 FMATVEC_ASSERT(i>=0, AT);
140 FMATVEC_ASSERT(j>=0, AT);
141 FMATVEC_ASSERT(i<M, AT);
142 FMATVEC_ASSERT(j<M, AT);
152 FMATVEC_ASSERT(i>=0, AT);
153 FMATVEC_ASSERT(j>=0, AT);
154 FMATVEC_ASSERT(i<M, AT);
155 FMATVEC_ASSERT(j<M, AT);
160 AT& ei(
int i,
int j) {
164 const AT& ei(
int i,
int j)
const {
168 AT& ej(
int i,
int j) {
172 const AT& ej(
int i,
int j)
const {
176 AT& e(
int i,
int j) {
177 return j > i ? ej(i,j) : ei(i,j);
180 const AT& e(
int i,
int j)
const {
181 return j > i ? ej(i,j) : ei(i,j);
201 constexpr
int size()
const {
return M;}
207 constexpr
int rows()
const {
return M;}
213 constexpr
int cols()
const {
return M;}
229 return CblasRowMajor;
252 inline Matrix<Symmetric,Fixed<M>,Fixed<M>,AT>& init(Eye,
const AT &val=1);
253 inline Matrix<Symmetric,Fixed<M>,Fixed<M>,AT>& init(Noinit,
const AT &a=AT()) {
return *
this; }
259 explicit inline operator std::vector<std::vector<AT>>()
const;
266 explicit inline Matrix(
const std::vector<std::vector<AT>> &m);
287 template <
int M,
class AT>
290 for(
int i=0; i<M; i++)
291 for(
int j=i; j<M; j++)
297 template <
int M,
class AT>
300 for(
int i=0; i<size(); i++) {
302 for(
int j=i+1; j<size(); j++) {
309 template <
int M,
class AT>
311 std::vector<std::vector<AT>> ret(rows());
312 for(
int r=0; r<rows(); r++) {
313 ret[r].resize(cols());
314 for(
int c=0; c<cols(); c++)
315 ret[r][c]=
operator()(r,c);
320 template <
int M,
class AT>
322 if(static_cast<int>(m.size())!=rows())
323 throw std::runtime_error(
"The number of rows does not match.");
324 for(
int r=0; r<rows(); r++) {
325 if(static_cast<int>(m[r].size())!=cols())
326 throw std::runtime_error(
"The rows of the input have different length.");
327 for(
int c=0; c<cols(); c++) {
330 if(r>c && abs(m[r][c]-m[c][r])>abs(m[r][c])*1e-13+1e-13)
331 throw std::runtime_error(
"The input is not symmetric.");
338 template <
int M,
class AT>
template <
class Type,
class Row,
class Col>
340 for(
int i=0; i<M; i++)
341 for(
int j=i; j<M; j++)
346 template <
int M,
class AT>
template <
class Row>
347 inline Matrix<Symmetric,Fixed<M>,Fixed<M>,AT>& Matrix<Symmetric,Fixed<M>,Fixed<M>,AT>::copy(
const Matrix<Symmetric,Row,Row,AT> &A) {
348 for(
int i=0; i<M; i++)
349 for(
int j=i; j<M; j++)
void resize(int n, int m)
Definition: fixed_symmetric_matrix.h:124
This is the basic matrix class for arbitrary matrices.
Definition: fmatvec.h:41
Shape class for symmetric matrices.
Definition: types.h:148
constexpr int size() const
Size.
Definition: fixed_symmetric_matrix.h:201
const AT & operator()(int i, int j) const
Element operator.
Definition: fixed_symmetric_matrix.h:151
const CBLAS_UPLO blasUplo() const
Symmetry convention.
Definition: fixed_symmetric_matrix.h:239
Matrix(const Matrix< Symmetric, Row, Row, AT > &A)
Copy Constructor.
Definition: fixed_symmetric_matrix.h:75
int cols() const
Number of columns.
Namespace fmatvec.
Definition: _memory.cc:28
AT * operator()()
Pointer operator.
Definition: fixed_symmetric_matrix.h:189
Matrix(const Matrix< Type, Row, Col, AT > &A)
Copy Constructor.
Definition: fixed_symmetric_matrix.h:86
constexpr int rows() const
Number of rows.
Definition: fixed_symmetric_matrix.h:207
const CBLAS_ORDER blasOrder() const
Storage convention.
Definition: fixed_symmetric_matrix.h:228
const AT * operator()() const
Pointer operator.
Definition: fixed_symmetric_matrix.h:195
int ldim() const
Leading dimension.
Definition: fixed_symmetric_matrix.h:219
Matrix< Symmetric, Fixed< M >, Fixed< M >, AT > & operator=(const Matrix< Type, Row, Col, AT > &A)
Assignment operator.
Definition: fixed_symmetric_matrix.h:107
constexpr int cols() const
Number of columns.
Definition: fixed_symmetric_matrix.h:213
int rows() const
Number of rows.
AT & operator()(int i, int j)
Element operator.
Definition: fixed_symmetric_matrix.h:138