22 #ifndef fixed_symmetric_matrix_h
23 #define fixed_symmetric_matrix_h
51 typedef AT value_type;
63 Matrix(
Init ini=INIT,
const AT &a=0) { init(a); }
64 Matrix(
Eye ini,
const AT &a=1) { init(ini,a); }
66 Matrix(
int m,
int n,
Init ini,
const AT &a=0) { init(a); }
67 Matrix(
int m,
int n,
Eye ini,
const AT &a=1) { init(ini,a); }
76 #ifndef FMATVEC_NO_SIZE_CHECK
77 assert(A.size() == M);
83 template<
class Type,
class Row,
class Col>
86 #ifndef FMATVEC_NO_SIZE_CHECK
87 assert(A.
rows() == M);
88 assert(A.
cols() == M);
98 throw std::runtime_error(
"A fixed symmetric matrix cannot be resized.");
118 #ifndef FMATVEC_NO_BOUNDS_CHECK
133 #ifndef FMATVEC_NO_BOUNDS_CHECK
143 AT& ei(
int i,
int j) {
147 const AT& ei(
int i,
int j)
const {
151 AT& ej(
int i,
int j) {
155 const AT& ej(
int i,
int j)
const {
159 AT& e(
int i,
int j) {
160 return j > i ? ej(i,j) : ei(i,j);
163 const AT& e(
int i,
int j)
const {
164 return j > i ? ej(i,j) : ei(i,j);
181 for(
int r=0; r<
rows(); r++) {
182 if(static_cast<int>(A[r].size())!=
cols())
183 throw std::runtime_error(
"The rows of the input have different length.");
184 for(
int c=0; c<
cols(); c++) {
186 if(r>c && fabs(A[r][c]-A[c][r])>fabs(A[r][c])*1e-13+1e-13)
187 throw std::runtime_error(
"The input is not symmetric.");
224 return CblasColMajor;
247 inline Matrix<Symmetric,Fixed<M>,Fixed<M>,AT>& init(Eye,
const AT &val=1);
248 inline Matrix<Symmetric,Fixed<M>,Fixed<M>,AT>& init(Noinit,
const AT &a=0) {
return *
this; }
254 inline operator std::vector<std::vector<AT> >()
const;
257 template <
int M,
class AT>
260 for(
int i=0; i<M; i++)
261 for(
int j=i; j<M; j++)
267 template <
int M,
class AT>
270 for(
int i=0; i<size(); i++) {
272 for(
int j=i+1; j<size(); j++) {
279 template <
int M,
class AT>
281 std::vector<std::vector<AT> > ret(rows());
282 for(
int r=0; r<rows(); r++) {
283 ret[r].resize(cols());
284 for(
int c=0; c<cols(); c++)
285 ret[r][c]=
operator()(r,c);
292 template <
int M,
class AT>
template <
class Type,
class Row,
class Col>
294 for(
int i=0; i<M; i++)
295 for(
int j=i; j<M; j++)
299 template <
int M,
class AT>
template <
class Row>
300 inline void Matrix<Symmetric,Fixed<M>,Fixed<M>,AT>::deepCopy(
const Matrix<Symmetric,Row,Row,AT> &A) {
301 for(
int i=0; i<M; i++)
302 for(
int j=i; j<M; j++)
void resize(int n, int m)
Definition: fixed_symmetric_matrix.h:96
This is the basic matrix class for arbitrary matrices.
Definition: fmatvec.h:41
Shape class for symmetric matrices.
Definition: types.h:116
int rows() const
Number of rows.
Definition: fixed_symmetric_matrix.h:202
const CBLAS_UPLO blasUplo() const
Symmetry convention.
Definition: fixed_symmetric_matrix.h:234
int rows() const
Number of rows.
const AT * operator()() const
Pointer operator.
Definition: fixed_symmetric_matrix.h:178
const AT & operator()(int i, int j) const
Element operator.
Definition: fixed_symmetric_matrix.h:132
int cols() const
Number of columns.
const CBLAS_ORDER blasOrder() const
Storage convention.
Definition: fixed_symmetric_matrix.h:223
int ldim() const
Leading dimension.
Definition: fixed_symmetric_matrix.h:214
AT * operator()()
Pointer operator.
Definition: fixed_symmetric_matrix.h:172
int cols() const
Number of columns.
Definition: fixed_symmetric_matrix.h:208
Basic shape class for matrices.
Definition: types.h:100
int size() const
Size.
Definition: fixed_symmetric_matrix.h:196
AT & operator()(int i, int j)
Element operator.
Definition: fixed_symmetric_matrix.h:117