68 std::ostream &operator<< (std::ostream &os, const TDenseMatrix<MT> &m);
97 { Alloc (r,c); Zero(); }
105 { Alloc (n,n); Zero(); }
112 { Alloc (m.rows, m.cols); memcpy (val, m.val, rc*
sizeof(MT)); }
142 { Alloc (r,c); memcpy (val, values, rc*
sizeof(MT)); }
178 inline void New (
int r,
int c) { New_dirty(r,c); Zero(); }
182 inline void Zero () { memset (val, 0, rc*
sizeof(MT)); }
185 inline void Zero (
int n) { New_dirty(n,n); Zero(); }
188 inline void Zero (
int r,
int c) { New_dirty(r,c); Zero(); }
195 inline void Identity (
int n) { New_dirty(n,n); Identity(); }
198 inline void Identity (
int r,
int c) { New_dirty(r,c); Identity(); }
201 inline MT
Get (
int r,
int c)
const {
202 dASSERT (r >= 0 && r < this->rows && c >= 0 && c < this->cols,
203 "Index out of range");
204 return val[r*this->cols + c];
208 inline void Set (
int r,
int c, MT v) {
209 dASSERT (r >= 0 && r < this->rows && c >= 0 && c < this->cols,
210 "Index out of range");
211 val[r*this->cols + c] = v;
215 inline MT operator() (
int r,
int c)
const {
219 inline MT &operator() (
int r,
int c) {
220 dASSERT (r >= 0 && r < this->rows && c >= 0 && c < this->cols,
221 "Index out of range");
222 return val[r*this->cols + c];
226 inline MT *ValPtr() {
return val; }
230 dASSERT (r >= 0 && r < this->rows,
"Index out of range");
238 int SparseRow (
int r, idxtype *ci, MT *rv)
const;
296 MT colmult (
int c1,
int c2);
316 {
TVector<MT> b(this->rows); Ax (x, b);
return b; }
321 for (
int i = 0; i < rc; i++) tmp.val[i] *= mt;
328 for (
int i = 0; i < rc; i++) tmp.val[i] /= mt;
334 for (
int i = 0; i < rc; i++) val[i] *= mt;
340 return *
this *= (MT)1 / mt;
413 MT *data_buffer() {
return val; }
414 const MT *data_buffer()
const {
return val; }
417 friend std::ostream &operator<< <> (std::ostream &os,
426 inline void Alloc (
int r,
int c) {
if ((rc = r*c)) val =
new MT[rc]; }
429 inline void Unlink () {
if (rc)
delete []val, rc = 0; }
432 void New_dirty (
int r,
int c);
447 #ifndef MATHLIB_IMPLEMENTATION
453 #endif // MATHLIB_IMPLEMENTATION
455 #endif // !__DNSMATRIX_H
TDenseMatrix(int r, int c, MT *values)
Create a dense r x c matrix with a list of values.
Definition: dnsmatrix.h:141
MT Get(int r, int c) const
Retrieve a matrix element.
Definition: dnsmatrix.h:201
friend TSymMatrix< MT > ATA(const TMatrix< MT > &A)
Return transp(*this) * *this as a symmetric matrix.
Definition: matrix.h:516
Definition: dnsmatrix.h:17
TDenseMatrix(int n)
Create a dense square matrix of size n x n.
Definition: dnsmatrix.h:104
TDenseMatrix(int r, int c)
Create a dense matrix of size r x c.
Definition: dnsmatrix.h:96
TVector< MT > RowSumSq() const
Returns a vector of sum of squares for each row.
TDenseMatrix()
Create a dense matrix of size 0 x 0.
Definition: dnsmatrix.h:87
void SetRow(int r, const TVector< MT > &rval)
Substitute a row of the matrix.
MatrixStorage
Definition: matrix.h:20
friend TCompRowMatrix< MT > catv(const TCompRowMatrix< MT > &A, const TCompRowMatrix< MT > &B)
Concatenate two matrices vertically.
TVector< MT > ColSum() const
Returns a vector of column sums.
~TDenseMatrix()
Destructor. De-allocates the matrix.
Definition: dnsmatrix.h:173
TVector< MT > Col(int c) const
Returns a vector containing a copy of column 'c'.
Compressed-row sparse matrix class.
Definition: cdmatrix.h:27
TVector< MT > Row(int r) const
Returns a vector containing a copy of row `r'.
Definition: dnsmatrix.h:229
dense matrix storage
Definition: matrix.h:21
void New(int r, int c)
Resize and reset the matrix.
Definition: dnsmatrix.h:178
friend TCompRowMatrix< MT > cath(const TCompRowMatrix< MT > &A, const TCompRowMatrix< MT > &B)
Concatenate two matrices horizontally.
TVector< MT > ColSumSq() const
Returns a vector of sum of squares for each column.
Virtual base class for all matrix types (dense and sparse)
Definition: matrix.h:43
TDenseMatrix(const TDenseMatrix< MT > &m)
Create a dense matrix as a copy of another dense matrix.
Definition: dnsmatrix.h:111
Dense matrix class.
Definition: crmatrix.h:38
MatrixStorage StorageType() const
Matrix storage class.
Definition: dnsmatrix.h:175
TVector< MT > RowSum() const
Returns a vector of row sums.
int SparseRow(int r, idxtype *ci, MT *rv) const
Returns a row of the matrix in sparse format.