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_) {
72 Matrix() : memory(), ele(0), n(0), lda(0) {
84 Matrix(
int n_,
Noinit) : memory(n_*n_), ele((AT*)memory.get()), n(n_), lda(n_) { }
85 Matrix(
int n_, Init ini=INIT,
const AT &a=0) : memory(n_*n_), ele((AT*)memory.get()), n(n_), lda(n_) { init(a); }
86 Matrix(
int n_, Eye ini,
const AT &a=1) : memory(n_*n_), ele((AT*)memory.get()), n(n_), lda(n_) { init(ini,a); }
87 Matrix(
int m_,
int n_, Noinit) : memory(n_*n_), ele((AT*)memory.get()), n(n_), lda(n_) { }
88 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); }
89 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); }
106 #ifndef FMATVEC_NO_SIZE_CHECK
111 template<
class Type,
class Row,
class Col>
113 #ifndef FMATVEC_NO_SIZE_CHECK
127 Matrix(
int n_, AT* ele_) : memory(), ele(ele_), n(n_), lda(n_) { }
140 Matrix<Symmetric,Ref,Ref,AT>& resize(
int n_, Noinit) {
143 ele = (AT*)memory.get();
147 Matrix<Symmetric,Ref,Ref,AT>& resize(
int n, Init ini=INIT,
const AT &a=0) {
return resize(n,Noinit()).
init(a); }
149 Matrix<Symmetric,Ref,Ref,AT>& resize(
int n, Eye ini,
const AT &a=1) {
return resize(n,Noinit()).
init(ini,a); }
159 inline Matrix<Symmetric,Ref,Ref,AT>& operator=(
const Matrix<Symmetric,Ref,Ref,AT> &A);
161 template<
class Type,
class Row,
class Col>
162 inline Matrix<Symmetric,Ref,Ref,AT>& operator=(
const Matrix<Type,Row,Col,AT> &A);
170 template<
class Type,
class Row,
class Col>
171 inline Matrix<Symmetric,Ref,Ref,AT>& operator<<(const Matrix<Type,Row,Col,AT> &A);
179 inline Matrix<Symmetric,Ref,Ref,AT>&
operator>>(
const Matrix<Symmetric,Ref,Ref,AT> &A);
193 #ifndef FMATVEC_NO_BOUNDS_CHECK
207 #ifndef FMATVEC_NO_BOUNDS_CHECK
217 AT& ei(
int i,
int j) {
221 const AT& ei(
int i,
int j)
const {
225 AT& ej(
int i,
int j) {
229 const AT& ej(
int i,
int j)
const {
233 AT& e(
int i,
int j) {
234 return j > i ? ej(i,j) : ei(i,j);
237 const AT& e(
int i,
int j)
const {
238 return j > i ? ej(i,j) : ei(i,j);
276 int ldim()
const {
return lda;};
286 return CblasColMajor;
316 inline Matrix<Symmetric,Ref,Ref,AT>& init(Eye,
const AT &a=1);
317 inline Matrix<Symmetric,Ref,Ref,AT>& init(Noinit,
const AT &a=0) {
return *
this; }
330 inline Matrix<General,Ref,Ref,AT>
operator()(
const Index &I,
const Index &J);
336 inline const Matrix<General,Ref,Ref,AT>
operator()(
const Index &I,
const Index &J)
const;
349 inline Matrix<Symmetric,Ref,Ref,AT>
operator()(
const Index &I);
355 inline const Matrix<Symmetric,Ref,Ref,AT>
operator()(
const Index &I)
const;
368 inline Matrix<General,Ref,Ref,AT>
operator()(
int i1,
int j1,
int i2,
int j2);
374 inline const Matrix<General,Ref,Ref,AT>
operator()(
int i1,
int j1,
int i2,
int j2)
const;
380 inline operator std::vector<std::vector<AT> >();
401 ele = (AT*)memory.get();
403 #ifndef FMATVEC_NO_SIZE_CHECK
404 assert(n == A.
size());
413 template <
class AT>
template<
class Type,
class Row,
class Col>
420 ele = (AT*)memory.get();
422 #ifndef FMATVEC_NO_SIZE_CHECK
424 assert(n == A.
rows());
434 template <
class AT>
template<
class Type,
class Row,
class Col>
437 #ifndef FMATVEC_NO_SIZE_CHECK
445 ele = (AT*)memory.get();
456 for(
int i=0; i<
rows(); i++)
457 for(
int j=i; j<
cols(); j++)
466 for(
int i=0; i<size(); i++) {
468 for(
int j=i+1; j<size(); j++) {
496 #ifndef FMATVEC_NO_BOUNDS_CHECK
512 #ifndef FMATVEC_NO_BOUNDS_CHECK
528 #ifndef FMATVEC_NO_BOUNDS_CHECK
537 #ifndef FMATVEC_NO_BOUNDS_CHECK
546 std::vector<std::vector<AT> > ret(rows());
547 for(
int r=0; r<rows(); r++) {
548 ret[r].resize(cols());
549 for(
int c=0; c<cols(); c++)
550 ret[r][c]=
operator()(r,c);
559 for(
int i=0; i<n; i++)
560 for(
int j=i; j<n; j++)
564 template <
class AT>
template <
class Type,
class Row,
class Col>
565 inline void Matrix<Symmetric,Ref,Ref,AT>::deepCopy(
const Matrix<Type,Row,Col,AT> &A) {
566 for(
int i=0; i<n; i++)
567 for(
int j=i; j<n; j++)
Matrix(const Matrix< General, Ref, Ref, AT > &A)
Element operator.
Definition: symmetric_matrix.h:105
AT & operator()(int i, int j)
Element operator.
Definition: symmetric_matrix.h:192
This is the basic matrix class for arbitrary matrices.
Definition: matrix.h:56
Shape class for symmetric matrices.
Definition: types.h:116
AT & operator()(int i, int j)
Standard constructor.
Definition: matrix.h:85
int rows() const
Number of rows.
Definition: general_matrix.h:270
int rows() const
Number of rows.
Definition: symmetric_matrix.h:264
int rows() const
Number of rows.
int end() const
Last element.
Definition: index.h:85
int cols() const
Number of columns.
const CBLAS_UPLO blasUplo() const
Symmetry convention.
Definition: symmetric_matrix.h:296
const CBLAS_ORDER blasOrder() const
Storage convention.
Definition: symmetric_matrix.h:285
Matrix< Symmetric, Ref, Ref, AT > & init(const AT &a)
Initialization.
Definition: symmetric_matrix.h:454
int cols() const
Number of columns.
Definition: symmetric_matrix.h:270
Matrix(int n_, AT *ele_)
Regular Constructor.
Definition: symmetric_matrix.h:127
This is a matrix class for general matrices.
Definition: general_matrix.h:40
int size() const
Size.
Definition: symmetric_matrix.h:258
AT * operator()()
Pointer operator.
Definition: symmetric_matrix.h:246
std::istream & operator>>(std::istream &is, Matrix< Type, Row, Col, AT > &A)
Matrix input.
Definition: matrix.h:170
const AT & operator()(int i, int j) const
Element operator.
Definition: symmetric_matrix.h:206
This is an index class for creating submatrices.
Definition: index.h:34
int ldim() const
Leading dimension.
Definition: symmetric_matrix.h:276
Matrix(const Matrix< Symmetric, Ref, Ref, AT > &A)
Copy Constructor.
Definition: symmetric_matrix.h:98
This is a matrix class for symmetric matrices.
Definition: symmetric_matrix.h:39
int start() const
First element.
Definition: index.h:79
const AT * operator()() const
Pointer operator.
Definition: symmetric_matrix.h:252
Matrix()
Standard constructor.
Definition: symmetric_matrix.h:72
~Matrix()
Destructor.
Definition: symmetric_matrix.h:131
int cols() const
Number of columns.
Definition: general_matrix.h:276