tmath::sparse::SparseMatrix Class Reference

The default sparse matrix class. More...

#include <sparsematrix.hpp>

Inheritance diagram for tmath::sparse::SparseMatrix:

Inheritance graph
[legend]
Collaboration diagram for tmath::sparse::SparseMatrix:

Collaboration graph
[legend]

List of all members.

Public Types

typedef Eigen::SparseMatrix
< TScalar
Base
typedef int TEigenIndex
typedef double TScalar
 the data type of the coefficients (real number)
typedef unsigned int TUnsignedIndex

Public Member Functions

SparseMatrix __neg__ () const
const char * __str__ () const
 transforms this objects into a string, required by SWIG
void Assign (SparseMatrix &other, bool keep_data=true)
TUnsignedIndex Cols () const
 returns the number of columns
TUnsignedIndex InnerNonZeros (TUnsignedIndex j) const
 returns the nonzeros of the j-th column
TUnsignedIndex InnerSize () const
 returns the number of inner elements
TUnsignedIndex NonZeros () const
 returns the number of nonzeros
SparseMatrix operator* (const double &x) const
SparseMatrix operator* (const SymSparseMatrix &x) const
SparseMatrix operator* (const SparseMatrix &x) const
Matrix operator* (const MatrixBlock &x) const
Matrix operator* (const Matrix &x) const
SparseMatrix operator+ (const SparseMatrix &x) const
SparseMatrix operator- (const SparseMatrix &x) const
SparseMatrix operator/ (const double &x) const
SparseMatrixoperator= (const SparseMatrix &other)
 The '=' operator for SparseMatrix.
TUnsignedIndex OuterSize () const
 returns the number of sparse column vectors
void Print (const std::string &format="%g ", TUnsignedIndex rows=20, TUnsignedIndex cols=20) const
void Prune (TScalar reference, TScalar epsilon)
 sets all elements with absolute value <= reference to zero and removes from storage
void Prune (TScalar reference)
 sets all elements with absolute value <= reference to zero and removes from storage
TUnsignedIndex Rows () const
 returns the number of rows
void SetZero ()
 sets the object to zero (clears it)
template<typename OtherDerived>
 SparseMatrix (const Eigen::SparseMatrixBase< OtherDerived > &x)
 copy constructor from Eigen objects
 SparseMatrix ()
 default constructor
 SparseMatrix (const TUnsignedIndex &nrow, const TUnsignedIndex &ncol=1)
 constructs a nrow*ncol matrix
 SparseMatrix (const SymSparseMatrix &ar)
 SparseMatrix (SymSparseMatrix &ar, bool keep_data=true)
 SparseMatrix (const SparseMatrix &ar)
 SparseMatrix (SparseMatrix &ar, bool keep_data=true)
 copy constructor
void Swap (SparseMatrix &other)
 swaps the contents of this object
SparseMatrix Transpose () const
 returns the transpose
virtual ~SparseMatrix ()
 destructor

Protected Attributes

unsigned int m_matrixType
 stores the matrix type


Detailed Description

The default sparse matrix class.

A class that represents storage for sparse linalg objects.

The storage scheme is column_major (FORTRAN). It basically provides basic features of the Eigen::SparseMatrix class, i.e. basic operators and assembly methods.

The storage scheme is described in the Eigen doc in detail. It should be noted that one can view any column_major sparse matrix as a set of 'ncols' sparse vectors. The sparse vectors are labeled by the index i ("outer iterator"), the access of the elements within these vectors is labeled by the Eigen::InnerIterator object it ("inner iterator"/ "inner loop").

The following methods can be used for storage:

(1) Sorted fill (fastest)

                                        SparseMatrix\<double,ColMajor> m(rows,cols);
                                        m.startFill(rows*cols*percent_of_non_zero); // estimate of the number of nonzeros (optional)
                                        for (int j=0; j\<cols; ++j)
                                                for (int i=0; i\<rows; ++i)
                                                        if (rand()\<percent_of_non_zero)
                                                                m.fill(i,j) = rand();
                                        m.endFill();

One has to fill the elements according to their internal index sort order (2) Fill by random inner access Herein one has to fill each outer index in its given sort order, but may fill the items into the currently active sparse vector in random order:

                                        SparseMatrix\<double,ColMajor> m(rows,cols);
                                        m.startFill(rows*cols*percent_of_non_zero); // estimate of the number of nonzeros (optional)
                                        for (int k=0; k\<cols; ++k)
                                        for (int i=0; i\<rows*percent_of_non_zero; ++i)
                                                m.fillrand(i,rand(0,cols)) = rand();
                                        m.endFill();

Member Function Documentation

SparseMatrix tmath::sparse::SparseMatrix::__neg__ (  )  const [inline]

returns unary minus (B=-A)

SparseMatrix tmath::sparse::SparseMatrix::operator* ( const double &  x  )  const

overrides the sparsematrix-scalar product.

Matrix tmath::sparse::SparseMatrix::operator* ( const Matrix x  )  const

overrides the sparsematrix-densematrix product.

SparseMatrix tmath::sparse::SparseMatrix::operator+ ( const SparseMatrix x  )  const

overrides the sparsematrix-sparsematrix sum.

SparseMatrix tmath::sparse::SparseMatrix::operator- ( const SparseMatrix x  )  const

overrides the sparsematrix-sparsematrix subtraction

SparseMatrix tmath::sparse::SparseMatrix::operator/ ( const double &  x  )  const

overrides the sparsematrix-scalar division.

void tmath::sparse::SparseMatrix::Print ( const std::string &  format = "%g ",
TUnsignedIndex  rows = 20,
TUnsignedIndex  cols = 20 
) const

prints the sparse matrix up to the given rows and columns (internally a temporary dense matrix will be created)


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

Generated on Wed Nov 17 17:36:01 2010 for 'tmath' Module Programming Interface by  doxygen 1.5.6