BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
belfem::SpMatrix Class Reference

Sparse matrix in CSR or CSC format. More...

#include <cl_SpMatrix.hpp>

Public Member Functions

 SpMatrix ()=default
 SpMatrix (const SpMatrix &)=delete
 SpMatrix (SpMatrix &&)=delete
 SpMatrix (Graph &aGraph, const enum SpMatrixType aType=SpMatrixType::CSC, const index_t aNumRows=0, const index_t aNumCols=0, const bool aSortGraph=true)
 SpMatrix (SpMatrixType aType, const index_t aNumRows, const index_t aNumCols, const index_t aNumNonZeros, const int_t *aIndices, const int_t *aPointers)
 SpMatrix (const string &aHDF5Path, const string aLabel="Matrix")
 SpMatrix (const hid_t aParent, const string aLabel="Matrix")
 SpMatrix (const Matrix< real > &aMatrix, const SpMatrixType aType=SpMatrixType::CSC)
 SpMatrix (SpMatrix *aParent)
 ~SpMatrix ()
const SpMatrixTypetype () const
 return the data type
void fill (const real aValue)
 write a specific value into all entries of the value container
index_t n_rows () const
 number of rows of this matrix
index_t n_cols () const
 number of columns of this matrix
index_t n_pointers () const
size_t memory () const
bool have_coo_indices () const
void set_type (const SpMatrixType aType)
 sets the type, must be called after set_sizes
index_t number_of_nonzeros () const
 number of nonzero values in this matrix
int_tpointers ()
 expose the pointers
const int_tpointers () const
 expose the pointers (const version)
int_tindices ()
 expose the index array
const int_tindices () const
 expose the index array ( const version )
int_trows ()
 expose the row indices
const int_trows () const
 expose the row indices ( const version )
int_tcols ()
 expose the col indices
const int_tcols () const
 expose the col indices ( const version )
realdata ()
 expose the data container
const realdata () const
 expose the data container ( const version )
realdata (const index_t aIndex)
 expose single entry in the data container
const realdata (const index_t aIndex) const
 expose single entry in the data containe ( const version )
int_t index (const index_t aRowIndex, const index_t aColIndex) const
int_t position (const index_t aRowIndex, const index_t aColIndex) const
 Position of ( aRowIndex, aColIndex ) in the value array, or mNumNonZeros when the entry is not in the sparsity pattern.
void positions_in_slice (const index_t aSlice, const int_t *aCols, const uint aNumCols, int_t *aPos) const
 Batched lookup: positions of aNumCols entries of one slice ( a row for CSR, a column for CSC ) in a single merge join over the slice, instead of aNumCols independent searches.
void sort_entries ()
 Ensure that the indices within each row (CSR) or column (CSC) are sorted in ascending order.
void set_indexing_base (const enum SpMatrixIndexingBase &aBasis)
 change the indexing base
void create_coo_indices ()
 create addidional indices that are needed by MUMPS
void free_coo_indices ()
 delete additional indices that are needed by MUMPS
void print (const string aLabel="SparseMatrix")
 print_t the matrix to the screen ( for debugging )
void print2 (const string aLabel="SparseMatrix")
 print_t the container indices on the screen ( for debugging )
int_t indexing_base () const
 returns the basis type of the matrix 0: c++ indexing 1: fortran indexing
void multiply (const Vector< real > &aX, Vector< real > &aY, const real aAlpha, const real aBeta, const bool aTransposedFlag=false)
 performs a matrix-vector multiplication
void multiply (const Vector< real > &aX, Vector< real > &aY)
 simple matrix-vector multiplication
void transpose ()
void save (const string &aPath, const string aLabel="Matrix", const enum FileMode aMode=FileMode::NEW)
 save matrix to a hdf5 file
void save (hid_t &aGroup, herr_t &aStatus)
 save matrix to a specific group in a HDF5 file
void load (const string &aPath, const string aLabel="Matrix")
 load matrix from a hdf5 file
void load (hid_t &aGroup, herr_t &aStatus)
 load matrix from a specific group in a hdf5 file
realoperator() (const index_t &aRowIndex, const index_t &aColIndex)
 access a specific value with write access
const realoperator() (const index_t &aRowIndex, const index_t &aColIndex) const
 access a specific value with read access
SpMatrixoperator= (const SpMatrix &aMatrix)
 copy operator
SpMatrixoperator= (SpMatrix &&aMatrix)
 move operator

Detailed Description

Sparse matrix in CSR or CSC format.

See also
BELFEM Sparse Matrix Module - Usage Guide

Constructor & Destructor Documentation

◆ SpMatrix() [1/9]

belfem::SpMatrix::SpMatrix ( )
default

◆ SpMatrix() [2/9]

belfem::SpMatrix::SpMatrix ( const SpMatrix & )
delete

◆ SpMatrix() [3/9]

belfem::SpMatrix::SpMatrix ( SpMatrix && )
delete

◆ SpMatrix() [4/9]

belfem::SpMatrix::SpMatrix ( Graph & aGraph,
const enum SpMatrixType aType = SpMatrixType::CSC,
const index_t aNumRows = 0,
const index_t aNumCols = 0,
const bool aSortGraph = true )

◆ SpMatrix() [5/9]

belfem::SpMatrix::SpMatrix ( SpMatrixType aType,
const index_t aNumRows,
const index_t aNumCols,
const index_t aNumNonZeros,
const int_t * aIndices,
const int_t * aPointers )

◆ SpMatrix() [6/9]

belfem::SpMatrix::SpMatrix ( const string & aHDF5Path,
const string aLabel = "Matrix" )

◆ SpMatrix() [7/9]

belfem::SpMatrix::SpMatrix ( const hid_t aParent,
const string aLabel = "Matrix" )

◆ SpMatrix() [8/9]

belfem::SpMatrix::SpMatrix ( const Matrix< real > & aMatrix,
const SpMatrixType aType = SpMatrixType::CSC )

◆ SpMatrix() [9/9]

belfem::SpMatrix::SpMatrix ( SpMatrix * aParent)
explicit

◆ ~SpMatrix()

belfem::SpMatrix::~SpMatrix ( )

Member Function Documentation

◆ cols() [1/2]

int_t * belfem::SpMatrix::cols ( )
inline

expose the col indices

◆ cols() [2/2]

const int_t * belfem::SpMatrix::cols ( ) const
inline

expose the col indices ( const version )

◆ create_coo_indices()

void belfem::SpMatrix::create_coo_indices ( )

create addidional indices that are needed by MUMPS

◆ data() [1/4]

real * belfem::SpMatrix::data ( )
inline

expose the data container

◆ data() [2/4]

const real * belfem::SpMatrix::data ( ) const
inline

expose the data container ( const version )

◆ data() [3/4]

real & belfem::SpMatrix::data ( const index_t aIndex)
inline

expose single entry in the data container

◆ data() [4/4]

const real & belfem::SpMatrix::data ( const index_t aIndex) const
inline

expose single entry in the data containe ( const version )

◆ fill()

void belfem::SpMatrix::fill ( const real aValue)

write a specific value into all entries of the value container

◆ free_coo_indices()

void belfem::SpMatrix::free_coo_indices ( )

delete additional indices that are needed by MUMPS

◆ have_coo_indices()

bool belfem::SpMatrix::have_coo_indices ( ) const
inline

◆ index()

int_t belfem::SpMatrix::index ( const index_t aRowIndex,
const index_t aColIndex ) const
inline

◆ indexing_base()

int_t belfem::SpMatrix::indexing_base ( ) const
inline

returns the basis type of the matrix 0: c++ indexing 1: fortran indexing

◆ indices() [1/2]

int_t * belfem::SpMatrix::indices ( )
inline

expose the index array

◆ indices() [2/2]

const int_t * belfem::SpMatrix::indices ( ) const
inline

expose the index array ( const version )

◆ load() [1/2]

void belfem::SpMatrix::load ( const string & aPath,
const string aLabel = "Matrix" )

load matrix from a hdf5 file

Parameters
aPathpath of hdf5 file
aLabeltitle of this matrix

◆ load() [2/2]

void belfem::SpMatrix::load ( hid_t & aGroup,
herr_t & aStatus )

load matrix from a specific group in a hdf5 file

◆ memory()

size_t belfem::SpMatrix::memory ( ) const

◆ multiply() [1/2]

void belfem::SpMatrix::multiply ( const Vector< real > & aX,
Vector< real > & aY )

simple matrix-vector multiplication

◆ multiply() [2/2]

void belfem::SpMatrix::multiply ( const Vector< real > & aX,
Vector< real > & aY,
const real aAlpha,
const real aBeta,
const bool aTransposedFlag = false )

performs a matrix-vector multiplication

c = alpha * A * b + beta * c

Parameters
aX
aY
aAlphascaling factor of the product
aBetascaling factor of the accumulator aY
aTransposedFlagmultiply with the transpose of the matrix

◆ n_cols()

index_t belfem::SpMatrix::n_cols ( ) const
inline

number of columns of this matrix

◆ n_pointers()

index_t belfem::SpMatrix::n_pointers ( ) const
inline

◆ n_rows()

index_t belfem::SpMatrix::n_rows ( ) const
inline

number of rows of this matrix

◆ number_of_nonzeros()

index_t belfem::SpMatrix::number_of_nonzeros ( ) const
inline

number of nonzero values in this matrix

◆ operator()() [1/2]

real & belfem::SpMatrix::operator() ( const index_t & aRowIndex,
const index_t & aColIndex )
inline

access a specific value with write access

◆ operator()() [2/2]

const real & belfem::SpMatrix::operator() ( const index_t & aRowIndex,
const index_t & aColIndex ) const
inline

access a specific value with read access

◆ operator=() [1/2]

SpMatrix & belfem::SpMatrix::operator= ( const SpMatrix & aMatrix)

copy operator

◆ operator=() [2/2]

SpMatrix & belfem::SpMatrix::operator= ( SpMatrix && aMatrix)

move operator

◆ pointers() [1/2]

int_t * belfem::SpMatrix::pointers ( )
inline

expose the pointers

◆ pointers() [2/2]

const int_t * belfem::SpMatrix::pointers ( ) const
inline

expose the pointers (const version)

◆ position()

int_t belfem::SpMatrix::position ( const index_t aRowIndex,
const index_t aColIndex ) const
inline

Position of ( aRowIndex, aColIndex ) in the value array, or mNumNonZeros when the entry is not in the sparsity pattern.

Works in either indexing base and for both CSR and CSC; the base is read from mPointers[ 0 ] and both branches are perfectly predicted in any loop that does not alternate between matrices.

◆ positions_in_slice()

void belfem::SpMatrix::positions_in_slice ( const index_t aSlice,
const int_t * aCols,
const uint aNumCols,
int_t * aPos ) const

Batched lookup: positions of aNumCols entries of one slice ( a row for CSR, a column for CSC ) in a single merge join over the slice, instead of aNumCols independent searches.

Parameters
aSlicerow index (CSR) or column index (CSC)
aColsthe other index of each entry, STRICTLY ascending
aNumColsnumber of entries
aPosoutput, one position per entry; an entry absent from the pattern gets mNumNonZeros

aCols must be strictly ascending - within one element the dof indices are unique, so equal neighbors cannot occur and the merge join does not handle them. Asserted in debug builds.

◆ print()

void belfem::SpMatrix::print ( const string aLabel = "SparseMatrix")

print_t the matrix to the screen ( for debugging )

◆ print2()

void belfem::SpMatrix::print2 ( const string aLabel = "SparseMatrix")

print_t the container indices on the screen ( for debugging )

◆ rows() [1/2]

int_t * belfem::SpMatrix::rows ( )
inline

expose the row indices

◆ rows() [2/2]

const int_t * belfem::SpMatrix::rows ( ) const
inline

expose the row indices ( const version )

◆ save() [1/2]

void belfem::SpMatrix::save ( const string & aPath,
const string aLabel = "Matrix",
const enum FileMode aMode = FileMode::NEW )

save matrix to a hdf5 file

Parameters
aPathpath of hdf5 file
aLabeltitle of this matrix
aModefile mode

◆ save() [2/2]

void belfem::SpMatrix::save ( hid_t & aGroup,
herr_t & aStatus )

save matrix to a specific group in a HDF5 file

◆ set_indexing_base()

void belfem::SpMatrix::set_indexing_base ( const enum SpMatrixIndexingBase & aBasis)

change the indexing base

◆ set_type()

void belfem::SpMatrix::set_type ( const SpMatrixType aType)

sets the type, must be called after set_sizes

◆ sort_entries()

void belfem::SpMatrix::sort_entries ( )

Ensure that the indices within each row (CSR) or column (CSC) are sorted in ascending order.

Unsorted entries are reordered in place together with their values. This is required for binary search in the index() methods.

Called automatically when loading from HDF5 or constructing from external arrays.

◆ transpose()

void belfem::SpMatrix::transpose ( )

◆ type()

const SpMatrixType & belfem::SpMatrix::type ( ) const
inline

return the data type


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