22 #ifndef symmetric_matrix_h
23 #define symmetric_matrix_h
53 const AT* elePtr(
int i,
int j)
const {
54 return j > i ? ele+i*lda+j : ele+i+j*lda;
57 AT* elePtr(
int i,
int j) {
58 return j > i ? ele+i*lda+j : ele+i+j*lda;
61 Matrix(
int n_,
int lda_, Memory<AT> memory_,
const AT* ele_) : memory(memory_), ele((AT*)ele_), n(n_), lda(lda_) {
68 typedef AT AtomicType;
74 Matrix() : memory(), ele(0), n(0), lda(0) {
86 Matrix(
int n_,
Noinit) : memory(n_*n_), ele((AT*)memory.get()), n(n_), lda(n_) { }
87 Matrix(
int n_, Init ini=INIT,
const AT &a=0) : memory(n_*n_), ele((AT*)memory.get()), n(n_), lda(n_) { init(a); }
88 Matrix(
int n_, Eye ini,
const AT &a=1) : memory(n_*n_), ele((AT*)memory.get()), n(n_), lda(n_) { init(ini,a); }
89 Matrix(
int m_,
int n_, Noinit) : memory(n_*n_), ele((AT*)memory.get()), n(n_), lda(n_) { }
90 Matrix(
int m_,
int n_, Init ini=INIT,
const AT &a=0) : memory(n_*n_), ele((AT*)memory.get()), n(n_), lda(n_) { init(a); }
91 Matrix(
int m_,
int n_, Eye ini,
const AT &a=1) : memory(n_*n_), ele((AT*)memory.get()), n(n_), lda(n_) { init(ini,a); }
108 #ifndef FMATVEC_NO_SIZE_CHECK
113 template<
class Type,
class Row,
class Col>
115 #ifndef FMATVEC_NO_SIZE_CHECK
129 Matrix(
int n_, AT* ele_) : memory(), ele(ele_), n(n_), lda(n_) { }
142 Matrix<Symmetric,Ref,Ref,AT>& resize(
int n_, Noinit) {
145 ele = (AT*)memory.get();
149 Matrix<Symmetric,Ref,Ref,AT>& resize(
int n, Init ini=INIT,
const AT &a=0) {
return resize(n,Noinit()).
init(a); }
151 Matrix<Symmetric,Ref,Ref,AT>& resize(
int n, Eye ini,
const AT &a=1) {
return resize(n,Noinit()).
init(ini,a); }
157 throw std::runtime_error(
"A symmetric matrix cannot have different dimensions for rows and columns.");
176 template<
class Type,
class Row,
class Col>
185 template<
class Type,
class Row,
class Col>
208 #ifndef FMATVEC_NO_BOUNDS_CHECK
222 #ifndef FMATVEC_NO_BOUNDS_CHECK
232 AT& ei(
int i,
int j) {
236 const AT& ei(
int i,
int j)
const {
240 AT& ej(
int i,
int j) {
244 const AT& ej(
int i,
int j)
const {
248 AT& e(
int i,
int j) {
249 return j > i ? ej(i,j) : ei(i,j);
252 const AT& e(
int i,
int j)
const {
253 return j > i ? ej(i,j) : ei(i,j);
291 int ldim()
const {
return lda;};
301 return CblasColMajor;
331 inline Matrix<Symmetric,Ref,Ref,AT>& init(Eye,
const AT &a=1);
332 inline Matrix<Symmetric,Ref,Ref,AT>& init(Noinit,
const AT &a=0) {
return *
this; }
345 inline Matrix<General,Ref,Ref,AT>
operator()(
const Range<Var,Var> &I,
const Range<Var,Var> &J);
351 inline const Matrix<General,Ref,Ref,AT>
operator()(
const Range<Var,Var> &I,
const Range<Var,Var> &J)
const;
364 inline Matrix<Symmetric,Ref,Ref,AT>
operator()(
const Range<Var,Var> &I);
370 inline const Matrix<Symmetric,Ref,Ref,AT>
operator()(
const Range<Var,Var> &I)
const;
383 inline Matrix<General,Ref,Ref,AT>
operator()(
int i1,
int j1,
int i2,
int j2);
389 inline const Matrix<General,Ref,Ref,AT>
operator()(
int i1,
int j1,
int i2,
int j2)
const;
395 inline operator std::vector<std::vector<AT> >();
416 ele = (AT*)memory.get();
418 #ifndef FMATVEC_NO_SIZE_CHECK
419 assert(n == A.
size());
428 template <
class AT>
template<
class Type,
class Row,
class Col>
435 ele = (AT*)memory.get();
437 #ifndef FMATVEC_NO_SIZE_CHECK
439 assert(n == A.
rows());
449 template <
class AT>
template<
class Type,
class Row,
class Col>
452 #ifndef FMATVEC_NO_SIZE_CHECK
460 ele = (AT*)memory.get();
471 for(
int i=0; i<
rows(); i++)
472 for(
int j=i; j<
cols(); j++)
481 for(
int i=0; i<size(); i++) {
483 for(
int j=i+1; j<size(); j++) {
511 #ifndef FMATVEC_NO_BOUNDS_CHECK
527 #ifndef FMATVEC_NO_BOUNDS_CHECK
543 #ifndef FMATVEC_NO_BOUNDS_CHECK
552 #ifndef FMATVEC_NO_BOUNDS_CHECK
561 std::vector<std::vector<AT> > ret(rows());
562 for(
int r=0; r<rows(); r++) {
563 ret[r].resize(cols());
564 for(
int c=0; c<cols(); c++)
565 ret[r][c]=
operator()(r,c);
574 for(
int i=0; i<n; i++)
575 for(
int j=i; j<n; j++)
579 template <
class AT>
template <
class Type,
class Row,
class Col>
580 inline void Matrix<Symmetric,Ref,Ref,AT>::deepCopy(
const Matrix<Type,Row,Col,AT> &A) {
581 for(
int i=0; i<n; i++)
582 for(
int j=i; j<n; j++)
Matrix(const Matrix< General, Ref, Ref, AT > &A)
Element operator.
Definition: symmetric_matrix.h:107
AT & operator()(int i, int j)
Element operator.
Definition: symmetric_matrix.h:207
This is the basic matrix class for arbitrary matrices.
Definition: fmatvec.h:41
Shape class for symmetric matrices.
Definition: types.h:116
AT & operator()(int i, int j)
Standard constructor.
Definition: matrix.h:86
int rows() const
Number of rows.
Definition: general_matrix.h:272
bool transposed()
The storage format of a symmetric matrix is fortran-storage order -> return always false...
Definition: symmetric_matrix.h:162
int rows() const
Number of rows.
Definition: symmetric_matrix.h:279
int rows() const
Number of rows.
int cols() const
Number of columns.
const CBLAS_UPLO blasUplo() const
Symmetry convention.
Definition: symmetric_matrix.h:311
const CBLAS_ORDER blasOrder() const
Storage convention.
Definition: symmetric_matrix.h:300
Matrix< Symmetric, Ref, Ref, AT > & init(const AT &a)
Initialization.
Definition: symmetric_matrix.h:469
int cols() const
Number of columns.
Definition: symmetric_matrix.h:285
Matrix(int n_, AT *ele_)
Regular Constructor.
Definition: symmetric_matrix.h:129
This is a matrix class for general matrices.
Definition: general_matrix.h:40
int size() const
Size.
Definition: symmetric_matrix.h:273
AT * operator()()
Pointer operator.
Definition: symmetric_matrix.h:261
std::istream & operator>>(std::istream &is, Matrix< Type, Row, Col, AT > &A)
Matrix input.
Definition: matrix.h:171
const AT & operator()(int i, int j) const
Element operator.
Definition: symmetric_matrix.h:221
int ldim() const
Leading dimension.
Definition: symmetric_matrix.h:291
Matrix(const Matrix< Symmetric, Ref, Ref, AT > &A)
Copy Constructor.
Definition: symmetric_matrix.h:100
This is a matrix class for symmetric matrices.
Definition: symmetric_matrix.h:39
int end() const
Last element.
Definition: range.h:95
const AT * operator()() const
Pointer operator.
Definition: symmetric_matrix.h:267
Matrix()
Standard constructor.
Definition: symmetric_matrix.h:74
void resize(int n, int m)
Definition: symmetric_matrix.h:155
This is an index class for creating submatrices.
Definition: range.h:44
~Matrix()
Destructor.
Definition: symmetric_matrix.h:133
int start() const
First element.
Definition: range.h:89
int cols() const
Number of columns.
Definition: general_matrix.h:278