C-XSC - A C++ Class Library for Extended Scientific Computing  2.5.4
cxsc::simatrix Class Reference

A sparse interval matrix. More...

#include <simatrix.hpp>

List of all members.

Public Member Functions

std::vector< int > & column_pointers ()
 Returns a reference to the vector containing the column pointers (the $ p $ array)
const std::vector< int > & column_pointers () const
 Returns a constant reference to the vector containing the column pointers (the $ p $ array)
real density () const
 Returns the density (the number of non-zeros divided by the number of elements) of the matrix.
void dropzeros ()
 Drops explicitly stored zeros from the data structure.
intervalelement (int i, int j)
 Returns a reference to the element (i,j) of the matrix.
void full (imatrix &A) const
 Creates a full matrix out of the sparse matrix and stores it in A. This should normally be done using the respective constructor of the dense matrix.
int get_nnz () const
 Returns the number of non-zero entries (including explicitly stored zeros).
simatrixoperator&= (const imatrix &B)
 Form the intersection of a sparse matrix and B and assign the result to it.
simatrixoperator&= (const imatrix_slice &B)
 Form the convex hull of a sparse matrix and B and assign the result to it.
simatrixoperator&= (const simatrix &B)
 Form the convex hull of a sparse matrix and B and assign the result to it.
const interval operator() (int i, int j) const
 Returns a copy of the element in row i and column j.
simatrix_slice operator() (const int, const int, const int, const int)
 Returns a slice of the matrix.
const simatrix_slice operator() (const int, const int, const int, const int) const
 Returns a slice of the matrix.
simatrix operator() (const intvector &pervec, const intvector &q)
 Performs a row and column permutation using two permutation vectors.
simatrix operator() (const intvector &pervec)
 Performs a row permutation using a permutation vector.
simatrix operator() (const intmatrix &P, const intmatrix &Q)
 Performs row and column permutations using the two permutation matrices P and Q. Faster than explicitly computing the product.
simatrix operator() (const intmatrix &P)
 Performs a row permutation using the permutation matrix P. Faster than explicitly computing the product.
simatrixoperator*= (const imatrix &B)
 Multiply the sparse matrix by B and assign the result to it.
simatrixoperator*= (const rmatrix &B)
 Multiply the sparse matrix by B and assign the result to it.
simatrixoperator*= (const rmatrix_slice &B)
 Multiply the sparse matrix by B and assign the result to it.
simatrixoperator*= (const imatrix_slice &B)
 Multiply the sparse matrix by B and assign the result to it.
simatrixoperator*= (const srmatrix &B)
 Multiply the sparse matrix by B and assign the result to it.
simatrixoperator*= (const simatrix &B)
 Multiply the sparse matrix by B and assign the result to it.
simatrixoperator*= (const real &r)
 Multiply all elements of the sparse matrix by r and assign the result to it.
simatrixoperator*= (const interval &r)
 Multiply all elements of the sparse matrix by r and assign the result to it.
simatrixoperator+= (const rmatrix &B)
 Add B to the sparse matrix and assign the result to it.
simatrixoperator+= (const imatrix &B)
 Add B to the sparse matrix and assign the result to it.
simatrixoperator+= (const rmatrix_slice &B)
 Add B to the sparse matrix and assign the result to it.
simatrixoperator+= (const imatrix_slice &B)
 Add B to the sparse matrix and assign the result to it.
simatrixoperator+= (const srmatrix &B)
 Add B to the sparse matrix and assign the result to it.
simatrixoperator+= (const simatrix &B)
 Add B to the sparse matrix and assign the result to it.
simatrixoperator-= (const rmatrix &B)
 Subtract B from the sparse matrix and assign the result to it.
simatrixoperator-= (const imatrix &B)
 Subtract B from the sparse matrix and assign the result to it.
simatrixoperator-= (const rmatrix_slice &B)
 Subtract B from the sparse matrix and assign the result to it.
simatrixoperator-= (const imatrix_slice &B)
 Subtract B from the sparse matrix and assign the result to it.
simatrixoperator-= (const srmatrix &B)
 Subtract B from the sparse matrix and assign the result to it.
simatrixoperator-= (const simatrix &B)
 Subtract B from the sparse matrix and assign the result to it.
simatrixoperator/= (const real &r)
 Divide all elements of the sparse matrix by r and assign the result to it.
simatrixoperator/= (const interval &r)
 Divide all elements of the sparse matrix by r and assign the result to it.
simatrixoperator= (const real &A)
 Assigns a real value to all elements of the matrix (resulting in a dense matrix!)
simatrixoperator= (const interval &A)
 Assigns an interval value to all elements of the matrix (resulting in a dense matrix!)
simatrixoperator= (const rmatrix &A)
 Assigns a dense matrix to the sparse matrix. Only the non zero entries of the dense matrix are used.
simatrixoperator= (const imatrix &A)
 Assigns a dense matrix to the sparse matrix. Only the non zero entries of the dense matrix are used.
simatrixoperator= (const rmatrix_slice &A)
 Assigns a dense matrix slice to the sparse matrix. Only the non zero entries of the dense matrix are used.
simatrixoperator= (const imatrix_slice &A)
 Assigns a dense matrix slice to the sparse matrix. Only the non zero entries of the dense matrix are used.
simatrixoperator= (const srmatrix &A)
 Assign a sparse real to a sparse interval matrix.
simatrixoperator= (const srmatrix_slice &)
 Assign a sparse matrix slice to a sparse matrix.
simatrixoperator= (const simatrix_slice &)
 Assign a sparse matrix slice to a sparse matrix.
simatrix_subv operator[] (const cxscmatrix_column &)
 Returns a column of the matrix as a sparse subvector object.
simatrix_subv operator[] (const int)
 Returns a row of the matrix as a sparse subvector object.
const simatrix_subv operator[] (const cxscmatrix_column &) const
 Returns a column of the matrix as a sparse subvector object.
const simatrix_subv operator[] (const int) const
 Returns a row of the matrix as a sparse subvector object.
simatrixoperator|= (const rmatrix &B)
 Form the convex hull of a sparse matrix and B and assign the result to it.
simatrixoperator|= (const imatrix &B)
 Form the convex hull of a sparse matrix and B and assign the result to it.
simatrixoperator|= (const rmatrix_slice &B)
 Form the convex hull of a sparse matrix and B and assign the result to it.
simatrixoperator|= (const imatrix_slice &B)
 Form the convex hull of a sparse matrix and B and assign the result to it.
simatrixoperator|= (const srmatrix &B)
 Form the convex hull of a sparse matrix and B and assign the result to it.
simatrixoperator|= (const simatrix &B)
 Form the convex hull of a sparse matrix and B and assign the result to it.
std::vector< int > & row_indices ()
 Returns a reference to the vector containing the row indices (the $ ind $ array)
const std::vector< int > & row_indices () const
 Returns a constant reference to the vector containing the row indices (the $ ind $ array)
 simatrix ()
 Standard constructor, creates an empty matrix of dimension 0x0.
 simatrix (const int r, const int c)
 Creates an empty matrix with r rows and c columns, pre-reserving space for 2*(r+c) elements.
 simatrix (const int r, const int c, const int e)
 Creates an empty matrix with r rows and c columns, pre-reserving space for e elements.
 simatrix (const int m, const int n, const int nnz, const intvector &rows, const intvector &cols, const ivector &values, const enum STORAGE_TYPE t=triplet)
 Creates a sparse matrix out of three vectors (arrays) forming a matrix stored in triplet, compressed row or compressed column storage.
 simatrix (const int m, const int n, const int nnz, const int *rows, const int *cols, const interval *values, const enum STORAGE_TYPE t=triplet)
 Creates a sparse matrix out of three arrays forming a matrix stored in triplet, compressed row or compressed column storage.
 simatrix (const srmatrix &A)
 Creates a sparse interval matrix out of a sparse real matrix A.
 simatrix (const rmatrix &A)
 Creates a sparse matrix out of a dense matrix A. Only the non zero elements of A are stored explicitly.
 simatrix (const imatrix &A)
 Creates a sparse matrix out of a dense matrix A. Only the non zero elements of A are stored explicitly.
 simatrix (const int ms, const int ns, const imatrix &A)
 Constructor for banded matrices.
 simatrix (const srmatrix_slice &)
 Creates a sparse matrix out of a sparse matrix slice.
 simatrix (const simatrix_slice &)
 Creates a sparse matrix out of a sparse matrix slice.
std::vector< interval > & values ()
 Returns a reference to the vector containing the stored values (the $ x $ array)
const std::vector< interval > & values () const
 Returns a constant reference to the vector containing the stored values (the $ x $ array)

Friends

simatrix abs (const simatrix &)
 Returns the componentwise absolute value as the interval hull of $ \{a_{ij} \mid a_{ij} \in [a_{ij}] \} $.
simatrix abs (const scimatrix &)
 Returns the componentwise absolute value of the matrix A.
srmatrix absmax (const simatrix &)
 Returns the componentwise maximum absolute value.
srmatrix absmin (const simatrix &)
 Returns the componentwise minimum absolute value.
int ColLen (const simatrix &)
 Returns the number of rows of the matrix.
srmatrix CompMat (const simatrix &)
 Returns Ostroswkis comparison matrix for A.
srmatrix diam (const simatrix &)
 Returns the componentwise diameter of A.
simatrix Id (const simatrix &)
 Return a sparse unity matrix of the same dimension as A.
simatrix Im (const scimatrix &)
 Returns the imaginary part of the matrix A.
srmatrix Inf (const simatrix &)
 Returns the Infimum of the matrix A.
int Lb (const simatrix &, int)
 Returns the lower index bound for the rows or columns of A.
srmatrix mid (const simatrix &)
 Returns the midpoint matrix for A.
std::istream & operator>> (std::istream &, simatrix_slice &)
 Standard input operator for sparse matrix slice.
std::istream & operator>> (std::istream &, simatrix_subv &)
 Standard input operator for subvectors.
simatrix Re (const scimatrix &)
 Returns the real part of the matrix A.
int RowLen (const simatrix &)
 Returns the number of columns of the matrix.
void SetLb (simatrix &, const int, const int)
 Sets the lower index bound of the rows (i==ROW) or columns (i==COL) to j.
void SetUb (simatrix &, const int, const int)
 Sets the upper index bound of the rows (i==ROW) or columns (i==COL) to j.
srmatrix Sup (const simatrix &)
 Returns the Supremum of the matrix A.
simatrix transp (const simatrix &)
 Returns the transpose of A.
int Ub (const simatrix &, int)
 Returns the upper index bound for the rows or columns of A.

Detailed Description

A sparse interval matrix.

Sparse matrices in C-XSC are stored in the Compressed Column Storage (CCS) format. The non zero entries of the matrix are stored in three arrays (STL-vectors) $ p $, $ ind $, $ x $. The array $ ind $ stores the row indices of the non zero elements, the array $ x $ the respective values (the $ i $-th element of $ ind $ corresponds to the i-th element of $ x $, $ i=0,\ldots,nnz-1 $, where $ nnz $ is the number of non zeros. The entries are sorted by column. The array $ p $ of size $ n+1 $ stores the starting indices for the entries of each column of the matrix, so that the entries of the $ j $-th column of the matrix are stored in the elements with index $ p[j] $ through $ p[j+1]-1 $ of the arrays $ x $ and $ ind $. The elements of each column are stored as sorted by the row indices, explicitly stored zeros are allowed.

The internal data structure uses 0-based indexing throughout. However, in the interface to the user (using the respective operators) every matrix possesses a lower and an upper row index bound $ lb_1 $, $ ub_1 $ and a lower and an upper column index bound $ lb_2 $, $ ub_2 $ of type int. By default, these indexes are 1-based.

It is possible to directly access the internal data structure through the appropriate member function to allow for easier interfacing with other sparse matrix libraries and writing of more efficient sparse matrix algorithms. In this case, the user has to take care that the data structure remains consistent with the format described above. If the user just works with the operators and functions provided by C-XSC, everything will be handled automatically by the C-XSC library.

All matrix and vector operators which require dot product computations use higher precision dot products provided by the dotprecision classes. The precision to be used for these implicit dot products can be choosen by setting the global variable opdotprec accordingly. A value of 0 means maximum accuracy (the default, always used by all older C-XSC versions), a value of 1 means double accuracy, a value of 2 or higher means k-fold double accuracy. Lower accuracy leads to (significantly) faster computing times, but also to less exact results. For all dot products with an interval result, error bounds are computed to guarantee a correct enclosure. For all other dot products approximations without error bounds are computed.

See also:
cxsc::dotprecision

Definition at line 69 of file simatrix.hpp.


Constructor & Destructor Documentation

cxsc::simatrix::simatrix ( const int  m,
const int  n,
const int  nnz,
const intvector rows,
const intvector cols,
const ivector values,
const enum STORAGE_TYPE  t = triplet 
) [inline]

Creates a sparse matrix out of three vectors (arrays) forming a matrix stored in triplet, compressed row or compressed column storage.

Creates a sparse matrix of dimension $ m \times n $ with the values from the three arrays rows, cols and values. These are interpreted according to the storage type t. For triplet rows and cols contains the indices of all non zero values and the array values contains the actual values. For compressed_column, the arrays are interpreted according to the compressed column storage format, where cols contains the column pointers. For compressed_row the arrays are interpreted according to the compressed row storage format, which is equivalent to compressed column storage with the role of the rows and columns interchanged.

In each case the arrays need not be sorted by rows or columns and may contain explicit zero entries.

Definition at line 143 of file simatrix.hpp.

cxsc::simatrix::simatrix ( const int  m,
const int  n,
const int  nnz,
const int *  rows,
const int *  cols,
const interval values,
const enum STORAGE_TYPE  t = triplet 
) [inline]

Creates a sparse matrix out of three arrays forming a matrix stored in triplet, compressed row or compressed column storage.

Creates a sparse matrix of dimension $ m \times n $ with the values from the three arrays rows, cols and values. These are interpreted according to the storage type t. For triplet rows and cols contains the indices of all non zero values and the array values contains the actual values. For compressed_column, the arrays are interpreted according to the compressed column storage format, where cols contains the column pointers. For compressed_row the arrays are interpreted according to the compressed row storage format, which is equivalent to compressed column storage with the role of the rows and columns interchanged.

In each case the arrays need not be sorted by rows or columns and may contain explicit zero entries.

Definition at line 254 of file simatrix.hpp.

cxsc::simatrix::simatrix ( const int  ms,
const int  ns,
const imatrix A 
) [inline]

Constructor for banded matrices.

Creates a sparse banded matrix of dimension $ ms \times ns $, whose bands are defined by the columns of the dense matrix A. The column inde range of A must be set appropriately: The columns of with negative indices are used for bands below the diagonal, the column with index 0 is used for the diagonal, and columns with positive index are use for bands above the diagonal.

Definition at line 416 of file simatrix.hpp.


Member Function Documentation

void cxsc::simatrix::dropzeros ( ) [inline]

Drops explicitly stored zeros from the data structure.

Dropping explicit zero entries can be essential when interfacing with other sparse matrix libraries. Some librares using the CCS storage format do not allow explicitly stored zeros.

Definition at line 473 of file simatrix.hpp.

interval& cxsc::simatrix::element ( int  i,
int  j 
) [inline]

Returns a reference to the element (i,j) of the matrix.

This function should only be used for write access. The indices i and j must be used according to the current index range of the matrix. A reference to the element (i,j) is returned. If the element is not stored explicitly, it is created as an explicit 0 entry. For read access to a single element, the ()-opeator should be used.

This function is faster than using the []-operator (for example A[i][j]), since it does not need to create a temporary subvector first.

Note that due to the underlying data structure the access to single elements of a sparse matrix is much more expensive than to the elements of a dense matrix.

Definition at line 579 of file simatrix.hpp.

Referenced by cxsc::simatrix_slice::element().

const interval cxsc::simatrix::operator() ( int  i,
int  j 
) const [inline]

Returns a copy of the element in row i and column j.

This operator can be used for read access only. The indices i and j must be used according to the current index range of the matrix. A copy of the element (i,j) is returned, or 0 if this element is not explicitly stored. For write access to a single element, the []-opeator or the member function element should be used.

Note that due to the underlying data structure the access to single elements of a sparse matrix is much more expensive than to the elements of a dense matrix.

Definition at line 558 of file simatrix.hpp.


Friends And Related Function Documentation

int Lb ( const simatrix A,
int  i 
) [friend]

Returns the lower index bound for the rows or columns of A.

If i==ROW, the lower index bound for the rows is returned, if i==COL, the lower index bound for the columns is returned.

Definition at line 1003 of file simatrix.hpp.

Referenced by operator()(), and simatrix().

std::istream& operator>> ( std::istream &  is,
simatrix_slice M 
) [friend]

Standard input operator for sparse matrix slice.

The input format is set by global flags, default is dense input. Use cout << SparseInOut; for sparse input or cout << MatrixMarketInOut; for input in matrix market format.

Definition at line 4369 of file simatrix.hpp.

void SetLb ( simatrix A,
const int  i,
const int  j 
) [friend]

Sets the lower index bound of the rows (i==ROW) or columns (i==COL) to j.

If i==ROW, the lower index bound for the rows of A ist set to j. if i==COL, the lower index bound of the columns is set to j. The upper index bound is automatically set according to the number of rows or columns of the matrix.

Definition at line 974 of file simatrix.hpp.

void SetUb ( simatrix A,
const int  i,
const int  j 
) [friend]

Sets the upper index bound of the rows (i==ROW) or columns (i==COL) to j.

If i==ROW, the upper index bound for the rows of A ist set to j. if i==COL, the upper index bound of the columns is set to j. The lower index bound is automatically set according to the number of rows or columns of the matrix.

Definition at line 989 of file simatrix.hpp.

int Ub ( const simatrix A,
int  i 
) [friend]

Returns the upper index bound for the rows or columns of A.

If i==COL, the upper index bound for the rows is returned, if i==COL, the upper index bound for the columns is returned.

Definition at line 1016 of file simatrix.hpp.

Referenced by simatrix().


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