3 #ifndef CH_MATRIX_CLASSES__SPARSMAT_HXX 4 #define CH_MATRIX_CLASSES__SPARSMAT_HXX 15 #ifndef CH_MATRIX_CLASSES__SYMMAT_HXX 24 #define SPARSE_ZERO_TOL 1e-60 133 #if (CONICBUNDLE_DEBUG>=1) 329 Real alpha,
Real beta,
int atrans,
int btrans);
338 Real alpha,
Real beta,
int atrans,
int btrans);
343 Real alpha,
Real beta,
int atrans,
int btrans);
561 void display(std::ostream& out,
599 Real alpha=1.,
Real beta=0.,
int atrans=0,
int btrans=0);
602 Real alpha=1.,
Real beta=0.,
int atrans=0,
int btrans=0);
605 Real alpha=1.,
Real beta=0.,
int atrans=0,
int btrans=0);
613 Real alpha=1.,
Real beta=0.,
int btrans=0);
617 Real alpha=1.,
Real beta=0.,
int atrans=0);
667 #if (CONICBUNDLE_DEBUG>=1) 714 {
return (*
this)(i%
nr,i/
nr);}
716 {
return (*
this)(i%
nr,i/
nr);}
741 {
return xbpeya(*
this,A,1.,1.); }
743 {
return xbpeya(*
this,A,-1.,1.); }
840 {
return xpeya(A,-1.);}
858 #ifndef CH_MATRIX_CLASSES__SPARSSYM_HXX #define chk_set_init(x, y)
CONICBUNDLE_DEBUG being undefined, the template function is removed. Otherwise it would allow to set ...
Definition: matop.hxx:1774
Integer dim() const
returns the dimension rows * columns when the matrix is regarded as a vector
Definition: sparsmat.hxx:196
int Integer
all integer numbers in calculations and indexing are of this type
Definition: matop.hxx:40
friend Real norm2(const Sparsemat &A)
returns the Frobenius norm of A, i.e., the square root of the sum of A(i,j)*A(i,j) over all i...
Definition: sparsmat.hxx:731
friend Symmatrix & rank2add(const Sparsemat &A, const Matrix &B, Symmatrix &C, Real alpha, Real beta, int trans)
returns C=beta*C+alpha*(A*B^T+B*A^T)/2 [or for transposed (A^T*B+B^T*A)/2]. If beta==0. then C is initiliazed to the correct size.
Sparsemat & delete_rows(const Indexmatrix &ind)
all rows indexed by vector ind are deleted, no row should appear twice in ind, remaining rows are mov...
friend Matrix sumcols(const Sparsemat &A)
returns a column vector holding the sum over all columns, i.e., A*(1 1 ... 1)^T
Matrix operator-(const Matrix &A, const Sparsemat &B)
returns a Matrix equal to A-B
Definition: sparsmat.hxx:800
Sparsemat col(Integer i) const
returns column i copied to a new sparse matrix
Matrix & xpeya(const Matrix &A, Real d=1.)
sets *this+=d*A and returns *this
Matrix colval
gives the value of the element at position i
Definition: sparsmat.hxx:90
Integer row_nonzeros(Integer i, Integer *startind=0) const
returns the number of nonzeros in row i; if nonzeros>0 and startind!=0 then the index of the first no...
friend Sparsemat rowsip(const Sparsemat &A, const Matrix *scaling)
returns the row vector of the squared Frobenius norm of all rows i of A, i.e., the sum of A(i...
int contains_support(const Sparsemat &A) const
returns 1 if A is of the same dimension and the support of A is contained in the support of *this...
void get_edge_rep(Indexmatrix &I, Indexmatrix &J, Matrix &val) const
stores the nz nonzero values of *this in I,J,val so that this(I(i),J(i))=val(i) for i=0...
double Real
all real numbers in calculations are of this type
Definition: matop.hxx:50
Sparsemat & delete_cols(const Indexmatrix &ind)
all colmuns indexed by vector ind are deleted, no column should appear twice in ind, remaining columns are moved up keeping their order, returns *this
Integer find_column(Integer i) const
given column index i, find the corresponding rowindex of colinfo or return -1 if the column is empty ...
#define SPARSE_ZERO_TOL
if the absolute value of an element is below this value, it is considered zero
Definition: sparsmat.hxx:24
friend std::istream & operator>>(std::istream &i, Sparsemat &v)
input format: nr nc nz \n i1 j1 val1\n i2 j2 val2\n ... inz jnz valnz\n
bool get_init() const
returns true if the matrix has been declared initialized (not needed if CONICBUNDLE_DEBUG is undefine...
Definition: sparsmat.hxx:142
const Indexmatrix & get_colinfo() const
returns information on nonzero columns, k by 3, listing: index, %nonzeros, first index in colindex/co...
Definition: sparsmat.hxx:265
friend void swap(Sparsemat &A, Sparsemat &B)
swap the content of the two sparse matrices A and B (involves no copying)
void display(std::ostream &out, int precision=0, int width=0, int screenwidth=0) const
displays a matrix in a pretty way for bounded screen widths; for variables of value zero default valu...
Matrix class for integral values of type Integer
Definition: indexmat.hxx:195
Sparsemat & insert_row(Integer i, const Sparsemat &v)
insert the row vector v before row i, 0<=i<= row dimension, for i==row dimension the row is appended ...
friend Real colip(const Sparsemat &A, Integer j, const Matrix *scaling)
returns the squared Frobenius norm of col i of A, i.e., the sum of A(i,j)*A(i,j) over all i with poss...
Matrix & init(const Matrix &A, Real d=1., int atrans=0)
initialize to *this=A*d where A may be transposed
Definition: matrix.hxx:1035
void dim(Integer &_nr, Integer &_nc) const
returns the number of rows in _nr and the number of columns in _nc
Definition: matrix.hxx:209
Mtype
serves for specifying the source (matrix class or function) of the error
Definition: matop.hxx:1585
Integer col_nonzeros(Integer i, Integer *startind=0) const
returns the number of nonzeros in column i; if nonzeros>0 and startind!=0 then the index of the first...
Real tol
>0, if abs(value)<tol, then value is taken to be zero
Definition: sparsmat.hxx:98
void dim(Integer &in_nr, Integer &in_nc) const
returns the number of rows in _nr and the number of columns in _nc
Definition: sparsmat.hxx:193
friend Matrix & genmult(const Sparsemat &A, const Matrix &B, Matrix &C, Real alpha, Real beta, int atrans, int btrans)
returns C=beta*C+alpha*A*B, where A and B may be transposed; C must not be equal to A and B; if beta=...
friend Symmatrix & scaledrankadd(const Sparsemat &A, const Matrix &D, Symmatrix &C, Real alpha, Real beta, int trans)
returns C=beta*C+alpha* A*D*A^T, where D is a vector representing a diagonal matrix and A may be tran...
friend Real trace(const Sparsemat &A)
returns the sum of the diagonal elements A(i,i) over all i
const Matrix & get_colval() const
returns the value vector of the column representation holding the value for each element ...
Definition: sparsmat.hxx:269
Sparsemat & xeya(const Sparsemat &A, Real d=1.)
sets *this=d*A and returns *this
Sparsemat()
empty matrix
Definition: sparsmat.hxx:692
Matrix class of symmetric matrices with real values of type Real
Definition: symmat.hxx:43
friend int equal(const Sparsemat &A, const Sparsemat &B, Real eqtol)
returns 1 if both matrices are identical, 0 otherwise
Matrix rowval
gives the value of the element at position i
Definition: sparsmat.hxx:95
Integer nc
number of columns
Definition: sparsmat.hxx:84
Header declaring the class CH_Matrix_Classes::Symmatrix for symmetric matrices with Real elements...
Sparsemat & concat_below(const Sparsemat &A)
concats sparse matrix A to the bottom of *this, A or *this may be the 0x0 matrix initally, returns *this
friend Sparsemat operator+(const Sparsemat &A, const Sparsemat &B)
returns a Sparsemat equal to A+B
Definition: sparsmat.hxx:754
Indexmatrix rowinfo
k by 3, for nonzero rows: index, # nonzeros, first index in colindex/colval
Definition: sparsmat.hxx:93
const Indexmatrix & get_rowindex() const
returns the index vector of the row representation holding the column index for each element ...
Definition: sparsmat.hxx:274
void set_tol(Real t)
set tolerance for recognizing zero values to t
Definition: sparsmat.hxx:165
Integer find_row(Integer i) const
given row index i, find the corresponding rowindex of rowinfo or return -1 if the row is empty ...
Indexmatrix rowindex
gives the column index of the element at position i, (sorted increasingly per row) ...
Definition: sparsmat.hxx:94
friend Sparsemat & xbpeya(Sparsemat &x, const Sparsemat &y, Real alpha, Real beta, int ytrans)
returns x= alpha*y+beta*x, where y may be transposed (ytrans=1); if beta==0. then x is initialized to...
error arises in a message of CH_Matrix_Classes::Sparsemat
Definition: matop.hxx:1590
friend Real ip(const Sparsemat &A, const Sparsemat &B)
returns the usual inner product of A and B, i.e., the sum of A(i,j)*B(i,j) over all i...
Sparsemat & init(const Sparsemat &A, Real d=1.)
initialize to *this=A*d
Definition: sparsmat.hxx:674
friend Symmatrix & rankadd(const Sparsemat &A, Symmatrix &C, Real alpha, Real beta, int trans)
returns C=beta*C+alpha* A*A^T, where A may be transposed; if beta==0. then C is initialized to the co...
Mtype get_mtype() const
returns the type of the matrix, MTmatrix
Definition: sparsmat.hxx:214
friend Real rowip(const Sparsemat &A, Integer i, const Matrix *scaling)
returns the squared Frobenius norm of row i of A, i.e., the sum of A(i,j)*A(i,j) over all j with poss...
Sparsemat & transpose()
transposes itself (swaps row and column representations, thus cheap)
Definition: sparsmat.hxx:718
Matrix Classes and Linear Algebra. See Matrix Classes (namespace CH_Matrix_Classes) for a quick intro...
Definition: PSCOracle.hxx:20
Real operator[](Integer i) const
returns value of element (i) of the matrix if regarded as vector of stacked columns [element (irowdim...
Definition: sparsmat.hxx:715
void set_init(bool)
after external initialization, call matrix.set_init(true) (not needed if CONICBUNDLE_DEBUG is undefin...
Definition: sparsmat.hxx:140
Matrix class of symmetric matrices with real values of type Real
Definition: sparssym.hxx:89
Indexmatrix & init(const Indexmatrix &A, Integer d=1)
initialize to *this=A*d
Sparsemat & concat_right(const Sparsemat &A)
concats sparse matrix A to the right of *this, A or *this may be the 0x0 matrix initally, returns *this
Mtype mtype
used for MatrixError templates (runtime type information was not yet existing)
Definition: sparsmat.hxx:83
int get_edge(Integer i, Integer &indi, Integer &indj, Real &val) const
stores element i of the get_edge_rep() function (ordered as in row representation); returns 1 if i is...
friend Sparsemat colsip(const Sparsemat &A, const Matrix *scaling)
returns the column vector of the squared Frobenius norm of all columns j of A, i.e., the sum of A(i,j)*A(i,j) over all i for each j with possibly (if scaling~=0) each term i multiplied by (*scaling)(i)
bool is_init
flag whether memory is initialized, it is only used if CONICBUNDLE_DEBUG is defined ...
Definition: sparsmat.hxx:100
Sparsemat & insert_col(Integer i, const Sparsemat &v)
insert a column before column i, 0<=i<= column dimension, for i==column dimension the column is appen...
Matrix class for real values of type Real
Definition: matrix.hxx:74
Indexmatrix colindex
gives the rowindex of the element at position i, (sorted increasingly per column) ...
Definition: sparsmat.hxx:89
Sparsemat rows(const Indexmatrix &ind) const
returns a sparse matrix of size vec.dim() x this->rowdim(), with row i a copy of row vec(i) of *this ...
Sparsemat cols(const Indexmatrix &ind) const
returns a sparse matrix of size this->rowdim() x vec.dim(), with column i a copy of column vec(i) of ...
friend Matrix sumrows(const Sparsemat &A)
returns a row vector holding the sum over all rows, i.e., (1 1 ... 1)*A
Matrix class of sparse matrices with real values of type Real
Definition: sparsmat.hxx:74
friend Real sum(const Sparsemat &A)
returns the sum over all elements of A, i.e., (1 1 ... 1)*A*(1 1 ... 1)^T
Definition: sparsmat.hxx:816
const Matrix & get_rowval() const
returns the value vector of the row representation holding the value for each element ...
Definition: sparsmat.hxx:276
const Indexmatrix & get_rowinfo() const
returns information on nonzero rows, k by 3, listing: index, %nonzeros, first index in rowindex/rowva...
Definition: sparsmat.hxx:272
Indexmatrix colinfo
k by 3, for nonzero columns: index, # nonzeros, first index in colindex/colval
Definition: sparsmat.hxx:88
const Indexmatrix & get_colindex() const
returns the index vector of the column representation holding the row index for each element ...
Definition: sparsmat.hxx:267
All derived classes share a common Memarray memory manager, which is generated with the first user an...
Definition: memarray.hxx:117
void init_to_zero()
initialize the matrix to a 0x0 matrix without storage
Definition: sparsmat.hxx:660
#define chk_range(i, j, ubi, ubj)
CONICBUNDLE_DEBUG being undefined, the template function is removed. Otherwise it would check...
Definition: matop.hxx:1772
friend Sparsemat operator*(const Sparsemat &A, const Sparsemat &B)
returns a Sparsemat equal to A*B
friend Sparsemat operator/(const Sparsemat &A, Real d)
ATTENTION: d is NOT checked for 0.
Definition: sparsmat.hxx:770
Sparsemat row(Integer i) const
returns row i copied to a new sparse matrix
Integer nr
number of rows
Definition: sparsmat.hxx:84
#define chk_init(x)
CONICBUNDLE_DEBUG being undefined, the template function is removed. Otherwise it would check...
Definition: matop.hxx:1761
friend std::ostream & operator<<(std::ostream &o, const Sparsemat &v)
output format: nr nc nz \n i1 j1 val1\n i2 j2 val2\n ... inz jnz valnz\n
Sparsemat & scale_cols(const Matrix &vec)
scales each column i of (*this) by vec(i), i.e., (*this)=(*this)*diag(vec), and returns (*this) ...
Sparsemat & scale_rows(const Matrix &vec)
scales each row i of (this) by vec(i), i.e., (*this)=diag(vec)(*this), and returns (*this) ...
Integer coldim() const
returns the column dimension
Definition: sparsmat.hxx:202
Integer rowdim() const
returns the row dimension
Definition: sparsmat.hxx:199
Matrix()
empty matrix
Definition: matrix.hxx:1082
friend Sparsemat abs(const Sparsemat &A)
returns a Sparsmat with elements abs((*this)(i,j)) for all i,j
Real operator()(Integer i, Integer j) const
returns value of element (i,j) of the matrix (rowindex i, columnindex j)
Integer nonzeros() const
returns the number of nonzeros
Definition: sparsmat.hxx:205