Hex  1.0
Hydrogen-electron collision solver
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions
CooMatrix Class Reference

Complex COO matrix. More...

#include <matrix.h>

Public Member Functions

 CooMatrix ()
 
 CooMatrix (size_t m, size_t n)
 
 CooMatrix (CooMatrix const &A)
 
 CooMatrix (size_t m, size_t n, NumberArray< long > const &i, NumberArray< long > const &j, NumberArray< Complex > const &x)
 
template<class T >
 CooMatrix (size_t m, size_t n, T a)
 
 ~CooMatrix ()
 
 operator Complex () const
 Convert 1×1 matrix to a complex number. More...
 
size_t rows () const
 
size_t cols () const
 
size_t size () const
 
lArray const & i () const
 
lArray const & j () const
 
cArray const & v () const
 
Complex operator() (size_t ix, size_t iy) const
 Index operator. Returns the existing value or zero. More...
 
template<class Functor >
CooMatrixsymm_populate_band (size_t d, Functor f)
 Symmetrical band populator. More...
 
template<class Functor >
CooMatrixpopulate (Functor f)
 Full populator. More...
 
CooMatrixoperator= (CooMatrix const &A)
 
void add (long i, long j, Complex v)
 Addition of an element to matrix. More...
 
CooMatrix transpose () const
 Transposition, implemented as an interchange of "i" and "j" data. More...
 
CooMatrixoperator+= (CooMatrix const &A)
 Addition. More...
 
CooMatrixoperator-= (CooMatrix const &A)
 Subtraction. More...
 
CooMatrixoperator*= (Complex c)
 Element-wise multiplication by complex number. More...
 
CooMatrix dot (const cArrayView B) const
 SpMV multiplication. More...
 
Complex ddot (CooMatrix const &B) const
 Double inner matrix-matrix product. More...
 
CooMatrixoperator*= (const cArrayView B)
 SpMV multiplication. More...
 
CooMatrixoperator/= (Complex c)
 Element-wise divide by a complex number. More...
 
void resize (size_t m, size_t n)
 Change dimension of the matrix. More...
 
CooMatrix reshape (size_t m, size_t n) const
 Change matrix shape. More...
 
cArray todense () const
 Convert matrix to dense column-major ordered 1D-array. More...
 
void sort ()
 Sort indices (by i_, then by j_) More...
 
bool sorted () const
 
CscMatrix tocsc () const
 Convert to CSC matrix. More...
 
CsrMatrix tocsr () const
 Convert to CSR matrix. More...
 
template<typename DenseMatrixType >
DenseMatrixType todense () const
 Convert to dense matrix of a given underlying type. More...
 
RowMatrix< Complextorow () const
 Convert to dense matrix (row-ordered). More...
 
ColMatrix< Complextocol () const
 Convert to dense matrix (column-ordered). More...
 
SymDiaMatrix todia (MatrixTriangle triangle=lower) const
 Convert to symmetric DIA format. More...
 
cArray solve (const cArrayView b, size_t eqs=1) const
 Solve matrix equation. More...
 
void write (const char *filename) const
 Write the matrix data to a file. More...
 
CooMatrix shake () const
 Shake the content, i.e. sum same element entries. More...
 
bool hdfsave (const char *name) const
 Save matrix to HDF file. More...
 
bool hdfload (const char *name)
 Load matrix from HDF file. More...
 

Detailed Description

Coordinate (ijv) storage format sparse matrix. The data are stored in four arrays,

* i, j, x, z
*

first two of which contain coordinates of nonzero element and the rest contain its real and imaginary part. Same coordinates amy be used several times; resulting element is then sum of these entries.

Constructor & Destructor Documentation

CooMatrix::CooMatrix ( )
inline
CooMatrix::CooMatrix ( size_t  m,
size_t  n 
)
inline
CooMatrix::CooMatrix ( CooMatrix const &  A)
inline
CooMatrix::CooMatrix ( size_t  m,
size_t  n,
NumberArray< long > const &  i,
NumberArray< long > const &  j,
NumberArray< Complex > const &  x 
)
inline
template<class T >
CooMatrix::CooMatrix ( size_t  m,
size_t  n,
a 
)
inline

Copy constructor initialized from dense array.

Parameters
mRow counz of new matrix.
nColumn count of new matrix.
aColumn-major ordered dense array with matrix elements. Only nonzero elements are copied into internal storage.
CooMatrix::~CooMatrix ( )
inline

Member Function Documentation

void CooMatrix::add ( long  i,
long  j,
Complex  v 
)
inline

Adds a new element to the matrix. If an existing coordinates are used, the numbers will be summed.

size_t CooMatrix::cols ( ) const
inline
Complex CooMatrix::ddot ( CooMatrix const &  B) const

Double inner matrix-matrix product, \( A : B \).

Note
Works only on sorted data.
Parameters
BOther matrix.
CooMatrix CooMatrix::dot ( const cArrayView  B) const
bool CooMatrix::hdfload ( const char *  name)
Parameters
nameFilename.
bool CooMatrix::hdfsave ( const char *  name) const
Parameters
nameFilename.
lArray const& CooMatrix::i ( ) const
inline
lArray const& CooMatrix::j ( ) const
inline
CooMatrix::operator Complex ( ) const
inline
Complex CooMatrix::operator() ( size_t  ix,
size_t  iy 
) const
inline
CooMatrix& CooMatrix::operator*= ( Complex  c)
inline
CooMatrix & CooMatrix::operator*= ( const cArrayView  B)
Parameters
BDense column-major ordered 1D-array. It's row count is assumed to be equal to the column count of *this and the column count is computed from the size of the array, which must be integer multiple of *this's column count.
CooMatrix& CooMatrix::operator+= ( CooMatrix const &  A)
inline
CooMatrix& CooMatrix::operator-= ( CooMatrix const &  A)
inline
CooMatrix& CooMatrix::operator/= ( Complex  c)
inline
CooMatrix& CooMatrix::operator= ( CooMatrix const &  A)
inline
template<class Functor >
CooMatrix& CooMatrix::populate ( Functor  f)
inline

Sets all values. The matrix can become easily dense!

Parameters
fObject compatible with signature:
* Complex (*) (long, long)
*
CooMatrix CooMatrix::reshape ( size_t  m,
size_t  n 
) const

Conserves volume, i.e. it holds

\[ m \cdot n = m_0 \cdot n_0 \]

Parameters
mNew row count.
nNew column coount.
void CooMatrix::resize ( size_t  m,
size_t  n 
)
inline
Warning
No row/column index range checking.
size_t CooMatrix::rows ( ) const
inline
CooMatrix CooMatrix::shake ( ) const
size_t CooMatrix::size ( ) const
inline
cArray CooMatrix::solve ( const cArrayView  b,
size_t  eqs = 1 
) const
inline

Solve the Ax = b problem, where "b" can be a matrix.

Parameters
bComplex vector containing column-major ordered data; it may be a flattened matrix.
eqsNumber of columns.
Returns
Array of roots in the same shape as "b".
void CooMatrix::sort ( )
bool CooMatrix::sorted ( ) const
inline
template<class Functor >
CooMatrix& CooMatrix::symm_populate_band ( size_t  d,
Functor  f 
)
inline

Sets values in the specified band. If there are already some values, these are added as independent (ijv)-triplets and thus summed together with existing entries.

Parameters
dBand halfwidth (full width is 2 * d + 1).
fObject compatible with signature:
* Complex (*) (long, long)
*
ColMatrix<Complex> CooMatrix::tocol ( ) const
inline
CscMatrix CooMatrix::tocsc ( ) const
CsrMatrix CooMatrix::tocsr ( ) const
cArray CooMatrix::todense ( ) const
template<typename DenseMatrixType >
DenseMatrixType CooMatrix::todense ( ) const
inline
SymDiaMatrix CooMatrix::todia ( MatrixTriangle  triangle = lower) const

Use "lower" for conversion of lower triangle, "upper" for conversion of upper triangle and "both" for conversion of the main diagonal only.

RowMatrix<Complex> CooMatrix::torow ( ) const
inline
CooMatrix CooMatrix::transpose ( ) const
inline
cArray const& CooMatrix::v ( ) const
inline
void CooMatrix::write ( const char *  filename) const
Parameters
filenameFilename.

Format of the fields i,j,x,z is:

* %d\t%d\t%g\t%g
*

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