98 TVector<MT> *x,
int nrhs,
double tol,
int maxit = 0,
116 int maxit = 0,
void (*clbk)(
void*) = 0);
143 int *iter = 0,
double *res = 0);
146 std::ostream &operator<< (std::ostream &os, const TMatrix<MT> &mat);
161 template<
class MT>
class TMatrix {
163 enum RC { ROW, COL };
179 { rows = nrows, cols = ncols; }
199 int Dim (RC rc)
const {
return (rc==ROW ? rows : cols); }
240 virtual void New (
int nrows,
int ncols);
251 virtual MT
Get (
int r,
int c)
const = 0;
301 virtual int SparseRow (
int r, idxtype *colidx, MT *val)
const = 0;
336 virtual void ColScale (
const TVector<MT> &scale) = 0;
339 virtual void RowScale (
const TVector<MT> &scale) = 0;
342 virtual void Unlink () = 0;
360 virtual void Transpone ()
364 virtual MT RowMult (
int r, MT *x)
const
365 { ERROR_UNDEF;
return 0; }
376 void Export (std::ostream &os)
const;
378 void Print (std::ostream &os = std::cout,
int n = 80)
const;
382 void PrintNzeroGraph (
char *fname);
417 int nrhs,
double tol,
int maxit = 0,
426 int nrhs,
double tol,
int maxit = 0,
430 friend std::ostream &operator<< <> (std::ostream &os,
473 int i, n = (rows < cols ? rows : cols);
475 for (i = 0; i < n; i++)
487 for (j = 0; j < cols; j++) {
488 cn[j] = (MT)l2norm (Col(j));
498 dASSERT (cols == x.
Dim(),
"Argument 1: vector has wrong size");
499 if (b.
Dim() != rows) b.
New(rows);
500 for (
int i = 0; i < rows; i++) b[i] = Row(i) & x;
508 dASSERT (rows == x.
Dim(),
"Argument 1: vector has wrong size");
509 if (b.
Dim() != cols) b.
New(cols);
510 for (
int i = 0; i < cols; i++) b[i] = Col(i) & x;
520 for (i = 0; i < nc; i++) {
522 for (j = 0; j <= i; j++)
523 ata(i,j) = col & A.
Col(j);
534 return PCG (*
this, b, x, tol, precon, maxit);
541 return PCG (*
this, b, x, tol, precon, maxit);
559 PCG (*
this, b, x, nrhs, tol, maxit, precon, res);
567 PCG (*
this, b, x, nrhs, tol, maxit, precon, res);
584 return BiCGSTAB (*
this, b, x, tol, precon, maxit);
591 return BiCGSTAB (*
this, b, x, tol, precon, maxit);
609 BiCGSTAB (*
this, b, x, nrhs, tol, maxit, precon, res);
617 BiCGSTAB (*
this, b, x, nrhs, tol, maxit, precon, res);
634 for (r = 0; r < rows; r++) {
635 for (c = 0; c < cols; c++) {
637 os << (c == cols-1 ?
'\n' :
' ');
647 int r, c, nc, minc, maxc, maxlen = 0;
652 for (r = 0; r < rows; r++) {
653 for (c = 0; c < cols; c++) {
656 os << Get(r,c) <<
' ';
662 while (minc < cols) {
664 if (maxc > cols) maxc = cols;
665 os <<
"*** Columns " << (minc+1) <<
" through " << maxc
667 for (r = 0; r < rows; r++) {
668 for (c = minc; c < maxc; c++) {
671 os << Get(r,c) <<
' ';
686 std::ofstream ofs (fname);
687 ofs <<
"P1" << std::endl;
688 ofs <<
"# CREATOR: TOAST TMatrix::PrintNzeroGraph" << std::endl;
689 ofs << cols <<
' ' << rows << std::endl;
690 for (i = r = 0; r < rows; r++) {
691 for (c = 0; c < cols; c++) {
692 ofs << (Get(r,c) != (MT)0 ?
'1' :
'0');
693 ofs << (++i % 35 ?
' ' :
'\n');
700 #endif // !__MATRIX_H
virtual void SetRow(int r, const TVector< MT > &row)
Substitute a row of the matrix.
Definition: matrix.h:283
void New(int dim)
Resize the vector.
Definition: vector.h:338
symmetric compressed row storage (sparse)
Definition: matrix.h:27
bool isFull() const
Return dense storage flag.
Definition: matrix.h:223
compressed column storage (sparse)
Definition: matrix.h:26
friend TSymMatrix< MT > ATA(const TMatrix< MT > &A)
Return transp(*this) * *this as a symmetric matrix.
Definition: matrix.h:516
Definition: dnsmatrix.h:17
TMatrix()
Create a matrix of size 0 x 0.
Definition: matrix.h:168
compressed row storage (sparse)
Definition: matrix.h:25
Definition: gsmatrix.h:48
virtual int SparseRow(int r, idxtype *colidx, MT *val) const =0
Returns a row of the matrix in sparse format.
virtual void New(int nrows, int ncols)
Resize and reset the matrix.
Definition: matrix.h:462
virtual TVector< MT > Col(int c) const =0
Returns a vector containing a copy of column 'c'.
MatrixStorage
Definition: matrix.h:20
TMatrix(int nrows, int ncols)
Create a matrix of logical size nrows x ncols.
Definition: matrix.h:178
MT operator()(int r, int c) const
Matrix element access (read only)
Definition: matrix.h:260
dense matrix storage
Definition: matrix.h:21
int Dim() const
Returns the size of the vector.
Definition: vector.h:295
virtual TVector< MT > ColNorm() const
Returns vector of column norms.
Definition: matrix.h:483
Virtual base class for all matrix types (dense and sparse)
Definition: matrix.h:43
int nCols() const
Return number of columns of the matrix.
Definition: matrix.h:213
virtual TVector< MT > Row(int r) const =0
Returns a vector containing a copy of row `r'.
virtual MT Get(int r, int c) const =0
Retrieve a matrix element.
virtual ~TMatrix()
Destroy the matrix.
Definition: matrix.h:191
void Export(std::ostream &os) const
Write matrix to ASCII stream.
Definition: matrix.h:631
int nRows() const
Return number of rows of the matrix.
Definition: matrix.h:206
bool isSparse() const
Return sparse storage flag.
Definition: matrix.h:219
int Dim(RC rc) const
Return a matrix dimension.
Definition: matrix.h:199
store diagonal matrix as vector
Definition: matrix.h:23
virtual MatrixStorage StorageType() const =0
Matrix storage class.
coordinate storage (sparse)
Definition: matrix.h:24
store lower triangle + diagonal of symmetric matrix
Definition: matrix.h:22
virtual TVector< MT > Diag() const
Returns the matrix diagonal as a vector.
Definition: matrix.h:471