53 dASSERT(r==c,
"Symmetric matrix must be square");
64 { Alloc (m.rows); memcpy (val, m.val, nz*
sizeof(MT)); }
77 inline void New (
int r,
int c) {
78 dASSERT(r==c,
"Symmetric matrix must be square");
84 inline void Zero () { memset (val, 0, nz*
sizeof(MT)); }
87 inline void Zero (
int n) { New_dirty(n); Zero(); }
90 inline void Zero (
int r,
int c) {
91 dASSERT(r==c,
"Symmetric matrix must be square");
100 inline void Identity (
int n) { New_dirty(n); Identity(); }
103 inline void Identity (
int r,
int c) {
104 dASSERT(r==c,
"Symmetric matrix must be square");
105 New_dirty(r); Identity();
109 inline MT
Get (
int r,
int c)
const {
110 dASSERT (r >= 0 && r < this->rows && c >= 0 && c < this->cols,
111 "Index out of range");
112 return val[Idx(r,c)];
116 inline const MT operator() (
int r,
int c)
const {
117 dASSERT (r >= 0 && r < this->rows && c >= 0 && c < this->cols,
118 "Index out of range");
119 return val[Idx(r,c)];
123 inline MT &operator() (
int r,
int c) {
124 dASSERT (r >= 0 && r < this->rows && c >= 0 && c < this->cols,
125 "Index out of range");
126 return val[Idx(r,c)];
131 {
for (
int i = 0; i < nz; i++) val[i] *= f;
return *
this; }
134 {
for (
int i = 0; i < nz; i++) val[i] /= f;
return *
this; }
142 int SparseRow (
int r, idxtype *ci, MT *rv)
const;
154 void AddDiag (
const MT &d);
177 dASSERT(this->rows == m.rows,
"Matrices have different size");
178 for (
int i = 0; i < nz; i++) val[i] += m.val[i];
184 dASSERT(this->rows == m.rows,
"Matrices have different size");
185 for (
int i = 0; i < nz; i++) val[i] -= m.val[i];
204 MT *data_buffer() {
return val; }
205 const MT *data_buffer()
const {
return val; }
211 inline int Idx (
int r,
int c)
const
212 {
return (r >= c ? c + ((r*(r+1)) >> 1) : r + ((c*(c+1)) >> 1)); }
216 inline void Alloc (
int n) {
if (n) val =
new MT[nz = (n*(n+1))/2]; }
219 inline void Unlink () {
if (nz)
delete[]val, nz = 0; }
222 void New_dirty (
int n);
241 #ifndef __SYMATRIX_CC
247 #endif // !__SYMATRIX_CC
249 #endif // !__SYMATRIX_H
Definition: dnsmatrix.h:17
TVector< MT > Row(int r) const
Returns a vector containing a copy of row `r'.
int SparseRow(int r, idxtype *ci, MT *rv) const
Returns a row of the matrix in sparse format.
MatrixStorage StorageType() const
Matrix storage class.
Definition: symatrix.h:74
MT Get(int r, int c) const
Retrieve a matrix element.
Definition: symatrix.h:109
TVector< MT > Col(int c) const
Returns a vector containing a copy of column 'c'.
Definition: symatrix.h:139
MatrixStorage
Definition: matrix.h:20
void New(int r, int c)
Resize and reset the matrix.
Definition: symatrix.h:77
Virtual base class for all matrix types (dense and sparse)
Definition: matrix.h:43
store lower triangle + diagonal of symmetric matrix
Definition: matrix.h:22