 libgenua Basic Geometry, Numerical Algorithms and Interfaces
CsrMatrix< Type, N > Class Template Reference

Detailed Description

template<class Type, int N = 1> class CsrMatrix< Type, N >

Compressed-row sparse matrix.

Generic CSR matrix with N components per row. N equal one yields a standard CSR matrix; larger N are used to represent a sparse matrix where N consecutive rows have the same sparsity pattern.

N != 1 can be used to represent sparse block matrices or gradient stencils, but note that some member functions do not make sense for N != 1, as they only are defined for plain element matrices.

ConnectMap

#include <csrmatrix.h>

Collaboration diagram for CsrMatrix< Type, N >:
[legend]

Public Member Functions

CsrMatrix (uint nr=0, uint nc=0)
empty matrix

CsrMatrix (const ConnectMap &s, uint nc=0)
construct matrix from sparsity

CsrMatrix (ConnectMap &&s, uint nc=0)
construct matrix from sparsity

CsrMatrix (const ConnectMap &s, const DVector< Type > &v, uint nc=0)
construct from sparsity and value vector

CsrMatrix (ConnectMap &&s, DVector< Type > &&v, uint nc=0)
construct from sparsity and value vector

CsrMatrix (uint nr, uint nc, const SparseBuilder< Type > &builder)
construct from sparse builder

void assign (uint nr, uint nc, const SparseBuilder< Type > &builder)
assign values from sorted builder

void appendRow (uint n, const uint colind[], const Type v[])
incremental assembly: append a row with column indices and values

uint nrows () const
number of sparse rows

uint ncols () const
number of sparse columns

uint nonzero () const
number of nonzero values (vectors)

uint ncols (uint kr) const
number of nonzero values in row kr

uint offset (uint kr) const
linear index offset for row kr

uint lindex (uint i, uint j) const
find linear index for (i,j)

uint uptrilix (uint i, uint j) const
find linear index for (i,j) if upper triangular symmetric part is stored

uint lotrilix (uint i, uint j) const
find linear index for (i,j) if lower triangular symmetric part is stored

const ConnectMapsparsity () const
access sparsity pattern directly

const Type * pointer () const
access value pointer directly

Type * pointer ()
access value pointer directly

const DVector< Type > & nzarray () const
access array of nonzero values

CsrMatrix< Type, N > & operator= (const Type &t)
set all values to t

const Type & operator[] (uint lix) const
access value by linear index (N == 1)

Type & operator[] (uint lix)
access value by linear index (N == 1)

const Type & operator() (uint ki, uint kj) const
access nonzero value by row/column

Type & operator() (uint ki, uint kj)
access nonzero value by row/column

const Type & value (uint lix, uint k) const
access component k of value by linear index

Type & value (uint lix, uint k)
access component k of value by linear index

void diagonal (DVector< Type > &dg) const
fill dg with the diagonal elements of *this

Type trace (bool absValue=false) const
return the trace, optionally of the absolute values

Type rowSum (uint k) const
compute row sum

void atomicAdd (uint lix, uint k, Type t)

void atomicAdd (uint lix, Type t)
atomically add to value lix, for the case N == 1

template<int M>
void assemble (const Indices &rmap, const Indices &cmap, const uint *vi, const SMatrix< M, M, Type > &Me)
add element matrix using row- and column index mapping

template<class AType >
void muladd (const AType a[], AType b[], AType beta=AType(1)) const
b <- A*x + beta*b : multiply with x, add result to b, low level form

template<class AType >
void muladd (size_t acols, size_t lda, const AType a[], size_t ldb, AType b[]) const
multiply with a, add result to b, low level form

template<class AType >
void muladdRow (uint i, const AType a[], AType b[]) const
multiply row i with a, set b, low level form

template<class AType >
void muladdRow (uint i, const DVector< AType > &a, SVector< N, AType > &b) const
multiply row i with a, set b, high level form

template<class AType >
void multiply (const AType a[], AType b[]) const
multiply with x, set b, low level form

template<class AType >
void multiply (size_t acols, size_t lda, const AType a[], size_t ldb, AType b[]) const
multiply with a, general low level form

template<class AType >
void muladd (const DVector< AType > &a, DVector< AType > &b, AType beta=AType(1)) const
multiply with x, add result to b, high level form

template<class AType >
void muladd (const DMatrix< AType > &a, DMatrix< AType > &b) const
multiply with x, add result to b, high level form

template<class AType >
void multiply (const DVector< AType > &a, DVector< AType > &b) const
multiply with x, set b, high level form

template<class AType >
void multiply (const DMatrix< AType > &a, DMatrix< AType > &b) const
multiply with x, set b, high level form

template<class AType >
void muladdTransposed (const AType a[], AType b[]) const
b += a^T * this = this^T * a, multiply transpose with a, add to b, low level form

template<class AType >
void muladdTransposed (AType alpha, const DVector< AType > &a, DVector< AType > &b) const
b += alpha * a^T * this = alpha * this^T * a, multiply transpose with a, add to b

template<class AType >
void muladdTransposed (const DVector< AType > &a, DVector< AType > &b) const
b += a^T * this = this^T * a, multiply transpose with a, add to b

template<class AType >
void multiplyTransposed (const AType a[], AType b[]) const
b = a^T * this = this^T * a, multiply transpose with a, set b, low level form

template<class AType >
void multiplyTransposed (const DVector< AType > &a, DVector< AType > &b) const
b = a^T * this = this^T * a, multiply transpose with a, set b

void scale (const DVector< Type > &a)
scale matrix rows

void setRow (uint kr, Type t)
set complete row to t

void scaleRow (uint kr, Type f)
scale a row with factor f

void scaleColumn (uint kc, Type f)
scale a column with factor f

void addRow (uint b, uint a, Type f=Type(1.0))
add row b to row a, assuming compatibility

modify by adding lambda to diagonal

void signaddDiagonalRel (Type lambda, uint offs)
modify by increasing magnitude of diagonal element

void signaddDiagonal (Type lambda, uint offs)
modify by increasing magnitude of diagonal element

void multDiagonal (Type lambda, uint offs)
modify by increasing magnitude of diagonal element

void domDiagonal (Type k, uint noff)
modify Jacobian by making diagonal terms more dominant

void dom3Diagonal (Type k)
modify Jacobian by making three-diagonal terms more dominant

void signadd3Diagonal (Type lambda, uint offs)
modify by increasing magnitude of diagonal element

void signuniDiagonal (Type lambda)
give uniform magnitude of diagonal elements

Type maxmagDiagonal () const
find largest magnitude of diagonal element

void trace (Type &lambda, uint offs)
compute trace of matrix

void abstrace (Type &lambda, uint offs)
compute "trace" of absolute values of diagonal elements of matrix

void diagfrac (Type &dqmin, Type &rvmin, uint offs)
compute "trace" of absolute values of diagonal elements of matrix

void absrowmin (Type &rvmin, uint offs)
compute "trace" of absolute values of diagonal elements of matrix

void rowmax (Type &rvmax, uint offs)
compute "trace" of absolute values of diagonal elements of matrix

template<typename AType >
void rank1update (const DVector< AType > &u, DVector< AType > &v)
perform an incomplete rank-1 update with u*v^T

template<typename AType >
void broydenUpdate (const DVector< AType > &df, DVector< AType > &dx)
perform an incomplete Broyden update of a Jacobian matrix

void upperTriangular (CsrMatrix< Type > &uptri) const
restrict to upper triangular part (including diagonal)

void dropTiny (Type threshold=std::numeric_limits< Type >::epsilon())
drop values with magnitude less than threshold

void rowPermutation (Indices &perm) const
Compute row permutation. More...

bool permuteByMetis (Indices &perm, Indices &iperm)
permute by calling METIS, if available, pass row/column permutation vector

void permute (const Indices &irowperm, const Indices &icolperm)
apply an arbitrary row/column permutation

void swap (ConnectMap &s, uint nc=0)
swap sparsity, reallocate storage

void swap (CsrMatrix< Type, N > &a)
swap contents with another matrix

XmlElement toXml (bool share=false) const
convert to xml representation

void fromXml (const XmlElement &xe)

float megabytes () const
performance statistics

void writePlain (std::ostream &os) const
plain text output for matlab etc

plain text input from text file for matlab and debugging

void writeMarket (std::ostream &os, bool writeZeros=true) const
write matrix market coordinate format (1-based, only scalar-valued matrices)

void writeBin (std::ostream &os) const
simple binary output

simple binary input

FFANodePtr toFFA () const
export to FFA format

bool fromFFA (const FFANodePtr &root)
import from FFA format

Static Public Member Functions

static void catColumns (const CsrMatrix< Type > &a, const CsrMatrix< Type > &b, CsrMatrix< Type > &ab)
concatenate columns of a and b to yield matrix ab

static void catRows (const CsrMatrix< Type > &a, const CsrMatrix< Type > &b, CsrMatrix< Type > &ab)
concatenate rows of a and b to yield matrix ab

static void assemble (const CsrMatrix< Type > &a11, const CsrMatrix< Type > &a12, const CsrMatrix< Type > &a21, const CsrMatrix< Type > &a22, CsrMatrix< Type > &b)
assemble from four blocks

Private Attributes

ConnectMap spty
connectivity data

DVector< Type > val
nonzero values

uint nrow
external dimensions for reference

Member Function Documentation

template<class Type, int N = 1>
 void CsrMatrix< Type, N >::rowPermutation ( Indices & perm ) const
inline

Compute row permutation.

Without changing the matrix itself, determine a row permutation which would move large (absolute) elements into the diagonal entries.

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