CH_Matrix_Classes::Sparsesym Class Reference
[Sparsesym (sparse, real, symmetric, n by n)]

Matrix class of symmetric matrices with real values of type Real More...

#include <sparssym.hxx>

Inheritance diagram for CH_Matrix_Classes::Sparsesym:

CH_Matrix_Classes::Memarrayuser

List of all members.

Public Member Functions

Constructors, Destructor, and Initialization (Members)
 Sparsesym ()
 empty matrix
 Sparsesym (const Sparsesym &A, Real d=1.)
 copy constructor, *this=d*A
 Sparsesym (Integer nr)
 initialize to zero-matrix of size nr*nr
 Sparsesym (Integer nr, Integer nz, const Integer *ini, const Integer *inj, const Real *va)
 initialize to size nr*nr and nz nonzeros so that this(ini[i],inj[i])=val[i] for i=0,..,nz-1; specify only one of (i,j) and (j,i), multiple elements are summed up.
 Sparsesym (Integer nr, Integer nz, const Indexmatrix &ini, const Indexmatrix &inj, const Matrix &va)
 initialize to size nr*nr and nz nonzeros so that this(ini(i),inj(i))=val[i] for i=0,..,nz-1; specify only one of (i,j) and (j,i), multiple elements are summed up.
void set_init (bool)
 after external initialization, call matrix.set_init(true) (not needed if CONICBUNDLE_DEBUG is undefined)
bool get_init () const
 returns true if the matrix has been declared initialized (not needed if CONICBUNDLE_DEBUG is undefined)
Sparsesyminit (const Sparsesym &, Real d=1.)
 initialize to *this=A*d
Sparsesyminit (const Matrix &, Real d=1.)
 initialize to *this=d*(A+transpose(A))/2., abs(values)<tol are removed from the support
Sparsesyminit (const Indexmatrix &, Real d=1.)
 initialize to *this=d*(A+transpose(A))/2., zeros are removed from the support
Sparsesyminit (const Symmatrix &, Real d=1.)
 initialize to *this=A*d, abs(values)<tol are removed from the support
Sparsesyminit (const Sparsemat &, Real d=1.)
 initialize to *this=d*(A+transpose(A))/2.
Sparsesyminit (Integer nr)
 initialize to zero-matrix of size nr*nr
Sparsesyminit (Integer nr, Integer nz, const Integer *ini, const Integer *inj, const Real *va)
 initialize to size nr*nr and nz nonzeros so that this(ini[i],inj[i])=val[i] for i=0,..,nz-1; specify only one of (i,j) and (j,i), multiple elements are summed up.
Sparsesyminit (Integer nr, Integer nz, const Indexmatrix &ini, const Indexmatrix &inj, const Matrix &va)
 initialize to size nr*nr and nz nonzeros so that this(ini(i),inj(i))=val[i] for i=0,..,nz-1; specify only one of (i,j) and (j,i), multiple elements are summed up.
Sparsesyminit_support (const Sparsesym &A, Real d=0.)
void set_tol (Real t)
 set tolerance for recognizing zero values to t
Conversions from other Matrix Classes (Members)
 Sparsesym (const Matrix &, Real d=1.)
 initialize to *this=d*(A+transpose(A))/2., abs(values)<tol are removed from the support
 Sparsesym (const Indexmatrix &, Real d=1.)
 initialize to *this=d*(A+transpose(A))/2., zeros are removed from the support
 Sparsesym (const Symmatrix &, Real d=1.)
 initialize to *this=A*d, abs(values)<tol are removed from the support
 Sparsesym (const Sparsemat &, Real d=1.)
 initialize to *this=d*(A+transpose(A))/2.
Size and Type Information (Members)
void dim (Integer &r, Integer &c) const
 returns the number of rows in _nr and the number of columns in _nc
Integer dim () const
 returns the dimension rows * columns when the matrix is regarded as a vector
Integer rowdim () const
 returns the row dimension
Integer coldim () const
 returns the column dimension
Integer nonzeros () const
 returns the number of nonzeros in the lower triangle (including diagonal)
Mtype get_mtype () const
 returns the type of the matrix, MTmatrix
Indexing and Submatrices (Members)
Real operator() (Integer i, Integer j) const
 returns value of element (i,j) of the matrix (rowindex i, columnindex j)
Real operator() (Integer i) const
 returns value of element (i) of the matrix if regarded as vector of stacked columns [element (irowdim, i/rowdim)]
Real operator[] (Integer i) const
 returns value of element (i) of the matrix if regarded as vector of stacked columns [element (irowdim, i/rowdim)]
const Indexmatrixget_colinfo () const
 returns information on nozero diagonal/columns, k by 4, listing: index (<0 for diagonal), # nonzeros, first index in colindex/colval, index in suppport submatrix
const Indexmatrixget_colindex () const
 returns the index vector of the column representation holding the row index for each element
const Matrixget_colval () const
 returns the value vector of the column representation holding the value for each element
const Indexmatrixget_suppind () const
 returns the index vector of the column representation holding the row index w.r.t. the principal support submatrix for each element
const Indexmatrixget_suppcol () const
 returns the vector listing in ascending order the original column indices of the principal support submatrix
void get_edge_rep (Indexmatrix &I, Indexmatrix &J, Matrix &val) const
 stores the nz nonzero values of the lower triangle of *this in I,J,val so that this(I(i),J(i))=val(i) for i=0,...,nz-1 and dim(I)=dim(J)=dim(val)=nz (ordered as in row representation)
int contains_support (const Sparsesym &A) const
 returns 1 if A is of the same dimension and the support of A is contained in the support of *this, 0 otherwise
int check_support (Integer i, Integer j) const
 returns 0 if (i,j) is not in the support, 1 otherwise
BLAS-like Routines (Members)
Sparsesymxeya (const Sparsesym &A, Real d=1.)
 sets *this=d*A and returns *this
Sparsesymxeya (const Matrix &A, Real d=1.)
 sets and returns *this=d*(A+transpose(A))/2. where abs(values)<tol are removed from the support
Sparsesymxeya (const Indexmatrix &A, Real d=1.)
 sets and returns *this=d*(A+transpose(A))/2. where zeros are removed from the support
Usual Arithmetic Operators (Members)
Sparsesymoperator= (const Sparsesym &A)
Sparsesymoperator+= (const Sparsesym &v)
Sparsesymoperator-= (const Sparsesym &v)
Sparsesym operator- () const
Sparsesymoperator*= (Real d)
Sparsesymoperator/= (Real d)
 ATTENTION: d is NOT checked for 0.
Sparsesymoperator= (const Matrix &A)
 sets *this=(A+transpose(A))/2. removing abs(values)<tol; returns *this
Sparsesymoperator= (const Indexmatrix &A)
 sets *this=(A+transpose(A))/2. removing zeros; returns *this
Sparsesymtranspose ()
 transposes itself (at almost no cost)
Connections to other Classes (Members)
Sparsesymxeya (const Symmatrix &A, Real d=1.)
 sets and returns *this=A*d where abs(values)<tol are removed from the support
Sparsesymxeya (const Sparsemat &A, Real d=1.)
 sets and returns *this=d.*(A+transpose(A))/2.
Sparsesymoperator= (const Symmatrix &A)
 sets and returns *this=A where abs(values)<tol are removed from the support
Symmatrix operator+ (const Symmatrix &A) const
Symmatrix operator- (const Symmatrix &A) const
Sparsesymoperator= (const Sparsemat &A)
 sets and returns *this=(A+transpose(A))/2.
Sparsemat sparsemult (const Matrix &A) const
 compute (*this)*A and return the result in a Sparsemat
Input, Output (Members)
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 values are used.

Private Member Functions

void init_to_zero ()
 initialize the matrix to a 0x0 matrix without storage
void update_support ()
 removes zeros and updates suppind and suppcol

Private Attributes

Mtype mtype
 used for MatrixError templates (runtime type information was not yet existing)
Integer nr
 number rows = number columns
Indexmatrix colinfo
 k by 4 matrix, for nonzero columns: index (<0 for diagonal), # nonzeros, first index in colindex/colval, index in suppport submatrix
Indexmatrix colindex
Matrix colval
 gives the rowindex of the element at position i, (sorted increasingly per column)
Indexmatrix suppind
 index of an element with respect to the principal submatrix spanned by the entire support
Indexmatrix suppcol
 the index of the support column in the original matrix
Real tol
 >0, if abs(value)<tol, then value is taken to be zero
bool is_init
 flag whether memory is initialized, it is only used if CONICBUNDLE_DEBUG is defined

Friends

class Indexmatrix
class Matrix
class Symmatrix
class Sparsemat
Indexing and Submatrices (Friends)
Matrix diag (const Sparsesym &A)
 returns the diagonal of A as a dense Matrix vector
Sparsesym sparseDiag (const Matrix &A, Real tol=SPARSE_ZERO_TOL)
 forms a sparse symmetrix matrix having vector A on its diagonal
void swap (Sparsesym &A, Sparsesym &B)
 swap the content of the two sparse matrices A and B (involves no copying)
BLAS-like Routines (Friends)
Sparsesymxbpeya (Sparsesym &x, const Sparsesym &y, Real alpha=1., Real beta=0.)
 returns x= alpha*y+beta*x, where y may be transposed (ytrans=1); if beta==0. then x is initialized to the correct size
Sparsesymxeyapzb (Sparsesym &x, const Sparsesym &y, const Sparsesym &z, Real alpha=1., Real beta=1.)
 returns x= alpha*y+beta*z; x is initialized to the correct size
Sparsesymsupport_rankadd (const Matrix &A, Sparsesym &C, Real alpha=1., Real beta=0., int trans=0)
 returns C=beta*C+alpha*AA^T (or A^TA), but only on the current support of C
Matrixgenmult (const Sparsesym &A, const Matrix &B, Matrix &C, Real alpha=1., Real beta=0., int btrans=0)
 returns C=beta*C+alpha*A*B, where A and B may be transposed; C must not be equal to B; if beta==0. then C is initialized to the correct size
Matrixgenmult (const Matrix &A, const Sparsesym &B, Matrix &C, Real alpha=1., Real beta=0., int atrans=0)
 returns C=beta*C+alpha*A*B, where A and B may be transposed; C must not be equal to B; if beta==0. then C is initialized to the correct size
Usual Arithmetic Operators (Friends)
Sparsesym operator+ (const Sparsesym &A, const Sparsesym &B)
Sparsesym operator- (const Sparsesym &A, const Sparsesym &B)
Sparsesym operator* (const Sparsesym &A, Real d)
Sparsesym operator* (Real d, const Sparsesym &A)
Sparsesym operator/ (const Sparsesym &A, Real d)
 ATTENTION: d is NOT checked for 0.
Matrix operator* (const Matrix &A, const Sparsesym &B)
Matrix operator* (const Sparsesym &A, const Matrix &B)
Matrix operator+ (const Matrix &A, const Sparsesym &B)
Matrix operator+ (const Sparsesym &A, const Matrix &B)
Matrix operator- (const Matrix &A, const Sparsesym &B)
Matrix operator- (const Sparsesym &A, const Matrix &B)
Sparsesym transpose (const Sparsesym &A)
 (drop it or use a constructor instead)
Connections to other Classes (Friends)
Symmatrix operator+ (const Sparsesym &A, const Symmatrix &B)
Symmatrix operator+ (const Symmatrix &A, const Sparsesym &B)
Symmatrix operator- (const Sparsesym &A, const Symmatrix &B)
Symmatrix operator- (const Symmatrix &A, const Sparsesym &B)
Real ip (const Symmatrix &A, const Sparsesym &B)
 returns the usual inner product of A and B, i.e., the sum of A(i,j)*B(i,j) over all i,j
Real ip (const Sparsesym &A, const Symmatrix &B)
 returns the usual inner product of A and B, i.e., the sum of A(i,j)*B(i,j) over all i,j
Matrixgenmult (const Sparsesym &A, const Sparsemat &B, Matrix &C, Real alpha=1., Real beta=0., int btrans=0)
 returns C=beta*C+alpha*A*B, where B may be transposed; if beta==0. then C is initialized to the correct size
Matrixgenmult (const Sparsemat &A, const Sparsesym &B, Matrix &C, Real alpha=1., Real beta=0., int atrans=0)
 returns C=beta*C+alpha*A*B, where A may be transposed; if beta==0. then C is initialized to the correct size
Matrix operator* (const Sparsesym &A, const Sparsemat &B)
Matrix operator* (const Sparsemat &A, const Sparsesym &B)
Elementwise Operations (Friends)
Sparsesym abs (const Sparsesym &A)
 sets (*this)(i,j)=abs((*this)(i,j)) for all i,j and returns *this
Numerical Methods (Friends)
Real trace (const Sparsesym &A)
 returns the sum of the diagonal elements A(i,i) over all i
Real ip (const Sparsesym &A, const Sparsesym &B)
 returns the usual inner product of A and B, i.e., the sum of A(i,j)*B(i,j) over all i,j
Real ip (const Matrix &A, const Sparsesym &B)
 returns the usual inner product of A and B, i.e., the sum of A(i,j)*B(i,j) over all i,j
Real ip (const Sparsesym &A, const Matrix &B)
 returns the usual inner product of A and B, i.e., the sum of A(i,j)*B(i,j) over all i,j
Real norm2 (const Sparsesym &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,j
Matrix sumrows (const Sparsesym &A)
 returns a row vector holding the sum over all rows, i.e., (1 1 ... 1)*A
Matrix sumcols (const Sparsesym &A)
 returns a column vector holding the sum over all columns, i.e., A*(1 1 ... 1)^T
Real sum (const Sparsesym &A)
 returns the sum over all elements of A, i.e., (1 1 ... 1)*A*(1 1 ... 1)^T
Equal (Members)
int equal (const Sparsesym &A, const Sparsesym &B, Real eqtol)
 returns 1 if both matrices are identical, 0 otherwise
Input, Output (Friends)
std::ostream & operator<< (std::ostream &o, const Sparsesym &v)
 output format (lower triangle): nr nz \n i1 j1 val1\n i2 j2 val2\n ... inz jnz valnz\n
std::istream & operator>> (std::istream &i, Sparsesym &v)
 input format (lower triangle): nr nz \n i1 j1 val1\n i2 j2 val2\n ... inz jnz valnz\n


Detailed Description

Matrix class of symmetric matrices with real values of type Real

Any matrix element can be indexed by (i,j) or directly by the one dimensional index (i+j*nr). The latter view directly corresponds to the vec() operator often used in the linear algebra literature, i.e., the matrix is transformed to a vector by stacking the columns on top of each other.

Internally the matrices colinfo, colindex, colval store the diagonal and the remaining lower triangle in columnwise order. For fast matrix multiplication generating sparse matrices additional information is stored in suppind and suppcol.

We now explain the representation of diagonal and columnwise lower triangle. Thereby the diagonal is treated like a separate column with negative index.

Suppose that 0<=k<=nr columns of diagonal and lower triangle of the symmetric nr*nr matrix contain nonzero elements, Then the Indexmatrix colinfo is a k by 4 matrix with one row for each nonzero column and the elements of row k give

Matrix colval is a vector with number of elements equal to the number of nonzeros in the lower triangle (including the diagonal). It stores the values of the nonzero elements of the diagonal and of the lower triangle in columnwise and then rowwise order, i.e., nonzero element (i1,j1) with i1>=j1 appears before a different nonzero element (i2,j2) with i2>=j2 iff (((i1==j1)&&(i2!=j2))||(j1<j2)||((j1==j2)&&(i1<i2)).

Indexmatrix colindex is of the same size as colval and stores for diagonal elemenets the row indices and for offdiagonal elements the rowindces minus the column index in the corresponding position. The shift of the offdiagonal indices helps to speed up some computations.

Note that in multplications with a (full or sparse) matrix it is beneficial to know the structure of principal submatrix that is spanned by the nonzero entries, i.e., to have available the indices of all columns/rows that contain nonzeros. This may differ considerably from the number of columns stored in colinfo, since one column of the lower triangle may cover many rows whose corresponding columns have no further nonzeros in the lower triangle. This information is stored in suppcol and suppind.

The Indexmatrix suppcol is a vector of dimension equal to the number of nonzero columns and contains, in increasing order, the indices of these columns.

The Indexmatrix suppind is arranged corresponding to colval and colindex, but in contrast to colindex it gives the row indices with respect to the principal support submatrix as given by suppcol.


Member Function Documentation

void CH_Matrix_Classes::Sparsesym::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 values are used.

Parameters:
out  output stream
precision  number of most significant digits, default=4
width  field width, default = precision+6
screenwidth  maximum number of characters in one output line, default = 80


The documentation for this class was generated from the following file:

Generated on Tue May 3 16:52:54 2011 for ConicBundle by  doxygen 1.5.6