22#ifndef fixed_symmetric_matrix_h
23#define fixed_symmetric_matrix_h
52 static constexpr bool isVector {
false};
53 using value_type = AT;
57 explicit Matrix(
Init ini=INIT,
const AT &a=AT()) { init(a); }
58 explicit Matrix(
Eye ini,
const AT &a=1) { init(ini,a); }
59 explicit Matrix(
int m,
int n,
Noinit ini) { FMATVEC_ASSERT(m==M && n==M, AT); }
60 explicit Matrix(
int m,
int n,
Init ini,
const AT &a=AT()) { FMATVEC_ASSERT(m==M && n==M, AT); init(a); }
61 explicit Matrix(
int m,
int n,
Eye ini,
const AT &a=1) { FMATVEC_ASSERT(m==M && n==M, AT); init(ini,a); }
77 FMATVEC_ASSERT(A.size() == M, AT);
86 template<
class Type,
class Row,
class Col>
88 FMATVEC_ASSERT(A.
rows() == M, AT);
89 FMATVEC_ASSERT(A.
cols() == M, AT);
107 template<
class Type,
class Row,
class Col>
109 FMATVEC_ASSERT(A.
rows() == A.
cols(), AT);
110 FMATVEC_ASSERT(M == A.
rows(), AT);
120 template<
class Type,
class Row,
class Col>
127 throw std::runtime_error(
"A fixed symmetric matrix cannot be resized.");
140 FMATVEC_ASSERT(i>=0, AT);
141 FMATVEC_ASSERT(j>=0, AT);
142 FMATVEC_ASSERT(i<M, AT);
143 FMATVEC_ASSERT(j<M, AT);
153 FMATVEC_ASSERT(i>=0, AT);
154 FMATVEC_ASSERT(j>=0, AT);
155 FMATVEC_ASSERT(i<M, AT);
156 FMATVEC_ASSERT(j<M, AT);
161 AT& ei(
int i,
int j) {
165 const AT& ei(
int i,
int j)
const {
169 AT& ej(
int i,
int j) {
173 const AT& ej(
int i,
int j)
const {
177 AT& e(
int i,
int j) {
178 return j > i ? ej(i,j) : ei(i,j);
181 const AT& e(
int i,
int j)
const {
182 return j > i ? ej(i,j) : ei(i,j);
202 constexpr int size()
const {
return M;}
208 constexpr int rows()
const {
return M;}
214 constexpr int cols()
const {
return M;}
230 return CblasRowMajor;
253 inline Matrix<Symmetric,Fixed<M>,Fixed<M>,AT>& init(Eye,
const AT &val=1);
254 inline Matrix<Symmetric,Fixed<M>,Fixed<M>,AT>& init(Noinit,
const AT &a=AT()) {
return *
this; }
260 explicit inline operator std::vector<std::vector<AT>>()
const;
267 explicit inline Matrix(
const std::vector<std::vector<AT>> &m);
288 template <
int M,
class AT>
291 for(
int i=0; i<M; i++)
292 for(
int j=i; j<M; j++)
298 template <
int M,
class AT>
301 for(
int i=0; i<size(); i++) {
303 for(
int j=i+1; j<size(); j++) {
310 template <
int M,
class AT>
312 std::vector<std::vector<AT>> ret(rows(),std::vector<AT>(cols()));
313 for(
int r=0; r<rows(); r++) {
314 for(
int c=r; c<cols(); c++) {
323 template <
int M,
class AT>
325 if(
static_cast<int>(m.size())!=rows())
326 throw std::runtime_error(
"The number of rows does not match.");
327 for(
int r=0; r<rows(); r++) {
328 if(
static_cast<int>(m[r].size())!=cols())
329 throw std::runtime_error(
"The rows of the input have different length.");
330 for(
int c=r; c<cols(); c++) {
333 if(c>r && abs(m[r][c]-m[c][r])>abs(m[r][c]*1e-13+1e-13))
334 throw std::runtime_error(
"The input is not symmetric.");
341 template <
int M,
class AT>
template <
class Type,
class Row,
class Col>
343 for(
int i=0; i<M; i++)
344 for(
int j=i; j<M; j++)
349 template <
int M,
class AT>
template <
class Row>
350 inline Matrix<Symmetric,Fixed<M>,Fixed<M>,AT>& Matrix<Symmetric,Fixed<M>,Fixed<M>,AT>::copy(
const Matrix<Symmetric,Row,Row,AT> &A) {
351 for(
int i=0; i<M; i++)
352 for(
int j=i; j<M; j++)
AT & operator()(int i, int j)
Element operator.
Definition: fixed_symmetric_matrix.h:139
constexpr int cols() const
Number of columns.
Definition: fixed_symmetric_matrix.h:214
Matrix(const Matrix< Type, Row, Col, AT > &A)
Copy Constructor.
Definition: fixed_symmetric_matrix.h:87
constexpr int size() const
Size.
Definition: fixed_symmetric_matrix.h:202
Matrix< Symmetric, Fixed< M >, Fixed< M >, AT > & operator=(const Matrix< Symmetric, Fixed< M >, Fixed< M >, AT > &A)=default
Assignment operator.
Matrix(const Matrix< Symmetric, Row, Row, AT > &A)
Copy Constructor.
Definition: fixed_symmetric_matrix.h:76
const AT & operator()(int i, int j) const
Element operator.
Definition: fixed_symmetric_matrix.h:152
Matrix(const Matrix< Symmetric, Fixed< M >, Fixed< M >, AT > &A)=default
Copy Constructor.
void resize(int n, int m)
Definition: fixed_symmetric_matrix.h:125
int ldim() const
Leading dimension.
Definition: fixed_symmetric_matrix.h:220
const AT * operator()() const
Pointer operator.
Definition: fixed_symmetric_matrix.h:196
AT * operator()()
Pointer operator.
Definition: fixed_symmetric_matrix.h:190
CBLAS_ORDER blasOrder() const
Storage convention.
Definition: fixed_symmetric_matrix.h:229
constexpr int rows() const
Number of rows.
Definition: fixed_symmetric_matrix.h:208
CBLAS_UPLO blasUplo() const
Symmetry convention.
Definition: fixed_symmetric_matrix.h:240
This is the basic matrix class for arbitrary matrices.
Definition: matrix.h:52
int rows() const
Number of rows.
int cols() const
Number of columns.
Shape class for symmetric matrices.
Definition: types.h:132
Namespace fmatvec.
Definition: _memory.cc:28