22 #ifndef fixed_symmetric_matrix_h 23 #define fixed_symmetric_matrix_h 51 typedef AT value_type;
54 explicit Matrix(
Init ini=INIT,
const AT &a=AT()) { init(a); }
55 explicit Matrix(
Eye ini,
const AT &a=1) { init(ini,a); }
56 explicit Matrix(
int m,
int n,
Noinit ini) { FMATVEC_ASSERT(m==M && n==M, AT); }
57 explicit Matrix(
int m,
int n,
Init ini,
const AT &a=AT()) { FMATVEC_ASSERT(m==M && n==M, AT); init(a); }
58 explicit Matrix(
int m,
int n,
Eye ini,
const AT &a=1) { FMATVEC_ASSERT(m==M && n==M, AT); init(ini,a); }
74 FMATVEC_ASSERT(A.size() == M, AT);
83 template<
class Type,
class Row,
class Col>
85 FMATVEC_ASSERT(A.
rows() == M, AT);
86 FMATVEC_ASSERT(A.
cols() == M, AT);
104 template<
class Type,
class Row,
class Col>
106 FMATVEC_ASSERT(A.
rows() == A.
cols(), AT);
107 FMATVEC_ASSERT(M == A.
rows(), AT);
117 template<
class Type,
class Row,
class Col>
124 throw std::runtime_error(
"A fixed symmetric matrix cannot be resized.");
137 FMATVEC_ASSERT(i>=0, AT);
138 FMATVEC_ASSERT(j>=0, AT);
139 FMATVEC_ASSERT(i<M, AT);
140 FMATVEC_ASSERT(j<M, AT);
150 FMATVEC_ASSERT(i>=0, AT);
151 FMATVEC_ASSERT(j>=0, AT);
152 FMATVEC_ASSERT(i<M, AT);
153 FMATVEC_ASSERT(j<M, AT);
158 AT& ei(
int i,
int j) {
162 const AT& ei(
int i,
int j)
const {
166 AT& ej(
int i,
int j) {
170 const AT& ej(
int i,
int j)
const {
174 AT& e(
int i,
int j) {
175 return j > i ? ej(i,j) : ei(i,j);
178 const AT& e(
int i,
int j)
const {
179 return j > i ? ej(i,j) : ei(i,j);
227 return CblasRowMajor;
250 inline Matrix<Symmetric,Fixed<M>,Fixed<M>,AT>& init(Eye,
const AT &val=1);
251 inline Matrix<Symmetric,Fixed<M>,Fixed<M>,AT>& init(Noinit,
const AT &a=AT()) {
return *
this; }
257 explicit inline operator std::vector<std::vector<AT>>()
const;
264 explicit inline Matrix(
const std::vector<std::vector<AT>> &m);
285 template <
int M,
class AT>
288 for(
int i=0; i<M; i++)
289 for(
int j=i; j<M; j++)
295 template <
int M,
class AT>
298 for(
int i=0; i<size(); i++) {
300 for(
int j=i+1; j<size(); j++) {
307 template <
int M,
class AT>
309 std::vector<std::vector<AT>> ret(rows());
310 for(
int r=0; r<rows(); r++) {
311 ret[r].resize(cols());
312 for(
int c=0; c<cols(); c++)
313 ret[r][c]=
operator()(r,c);
318 template <
int M,
class AT>
320 if(static_cast<int>(m.size())!=rows())
321 throw std::runtime_error(
"The number of rows does not match.");
322 for(
int r=0; r<rows(); r++) {
323 if(static_cast<int>(m[r].size())!=cols())
324 throw std::runtime_error(
"The rows of the input have different length.");
325 for(
int c=0; c<cols(); c++) {
328 if(r>c && abs(m[r][c]-m[c][r])>abs(m[r][c])*1e-13+1e-13)
329 throw std::runtime_error(
"The input is not symmetric.");
336 template <
int M,
class AT>
template <
class Type,
class Row,
class Col>
338 for(
int i=0; i<M; i++)
339 for(
int j=i; j<M; j++)
344 template <
int M,
class AT>
template <
class Row>
345 inline Matrix<Symmetric,Fixed<M>,Fixed<M>,AT>& Matrix<Symmetric,Fixed<M>,Fixed<M>,AT>::copy(
const Matrix<Symmetric,Row,Row,AT> &A) {
346 for(
int i=0; i<M; i++)
347 for(
int j=i; j<M; j++)
int size() const
Size.
Definition: fixed_symmetric_matrix.h:199
void resize(int n, int m)
Definition: fixed_symmetric_matrix.h:122
This is the basic matrix class for arbitrary matrices.
Definition: fmatvec.h:41
Shape class for symmetric matrices.
Definition: types.h:148
const AT & operator()(int i, int j) const
Element operator.
Definition: fixed_symmetric_matrix.h:149
const CBLAS_UPLO blasUplo() const
Symmetry convention.
Definition: fixed_symmetric_matrix.h:237
Matrix(const Matrix< Symmetric, Row, Row, AT > &A)
Copy Constructor.
Definition: fixed_symmetric_matrix.h:73
int cols() const
Number of columns.
Definition: fixed_symmetric_matrix.h:211
int cols() const
Number of columns.
Namespace fmatvec.
Definition: _memory.cc:28
AT * operator()()
Pointer operator.
Definition: fixed_symmetric_matrix.h:187
Matrix(const Matrix< Type, Row, Col, AT > &A)
Copy Constructor.
Definition: fixed_symmetric_matrix.h:84
const CBLAS_ORDER blasOrder() const
Storage convention.
Definition: fixed_symmetric_matrix.h:226
const AT * operator()() const
Pointer operator.
Definition: fixed_symmetric_matrix.h:193
int ldim() const
Leading dimension.
Definition: fixed_symmetric_matrix.h:217
Matrix< Symmetric, Fixed< M >, Fixed< M >, AT > & operator=(const Matrix< Type, Row, Col, AT > &A)
Assignment operator.
Definition: fixed_symmetric_matrix.h:105
int rows() const
Number of rows.
AT & operator()(int i, int j)
Element operator.
Definition: fixed_symmetric_matrix.h:136
int rows() const
Number of rows.
Definition: fixed_symmetric_matrix.h:205