12#ifndef BELFEM_CL_SPMATRIX_HPP
13#define BELFEM_CL_SPMATRIX_HPP
68 int_t mNumNonZeros = 0;
71 int_t mPointerSize = 0;
74 int_t * mPointers =
nullptr;
76 int_t * mRows =
nullptr;
78 int_t * mColumns =
nullptr;
81 real * mValues =
nullptr;
83 bool mHaveCooIndices =
false;
120 const bool aSortGraph =
true );
128 const int_t * aIndices,
129 const int_t * aPointers );
134 SpMatrix(
const string & aHDF5Path,
const string aLabel=
"Matrix" );
138 SpMatrix(
const hid_t aParent,
const string aLabel=
"Matrix" );
328 const index_t aColIndex )
const;
342 const index_t aColIndex )
const;
365 int_t * aPos )
const;
413 print(
const string aLabel=
"SparseMatrix" );
421 print2(
const string aLabel=
"SparseMatrix" );
450 const bool aTransposedFlag=
false );
478 save(
const string & aPath,
479 const string aLabel=
"Matrix",
500 load(
const string & aPath,
501 const string aLabel=
"Matrix"
532 const index_t & aColIndex )
const;
559 check_graph(
Graph & aGraph );
567 tidy_graph(
Graph & aGraph );
572 create_csr_indices(
Graph & aGraph );
577 create_csc_indices(
Graph & aGraph );
590 set_nnz(
const index_t aNumberOfNonzeros );
628 update_from_parent();
679 return (
index_t ) mPointerSize;
687 return mHaveCooIndices;
695 return (
index_t ) mNumNonZeros;
806 "Index %lu for sparse matix out of bounds ( must be less than %lu )",
807 (
long unsigned int ) aIndex,
808 (
long unsigned int ) mNumNonZeros );
810 return mValues[ aIndex ];
819 "Index %lu for sparse matix out of bounds ( must be less than %lu )",
820 (
long unsigned int ) aIndex,
821 (
long unsigned int ) mNumNonZeros );
823 return mValues[ aIndex ];
831 return mPointers !=
nullptr ? mPointers[ 0 ] : 0;
840 (
long unsigned int ) aRowIndex ,
841 (
long unsigned int ) mNumRows );
844 (
long unsigned int ) aColIndex ,
845 (
long unsigned int ) mNumCols );
850 const int_t tBase = mPointers[ 0 ];
853 const index_t tSlice = tIsCsr ? aRowIndex : aColIndex ;
854 const int_t tTarget = (
int_t )( tIsCsr ? aColIndex : aRowIndex ) + tBase ;
856 const int_t * tIndices = tIsCsr ? mColumns : mRows ;
858 const int_t tBegin = mPointers[ tSlice ] - tBase ;
859 const int_t tEnd = mPointers[ tSlice + 1 ] - tBase ;
878 const int_t * tFound = std::lower_bound( tIndices + tBegin,
882 return ( tFound < tIndices + tEnd && *tFound == tTarget )
883 ? (
int_t )( tFound - tIndices )
892 return this->
position( aRowIndex, aColIndex );
905 "operator() called while matrix is in Fortran indexing mode. "
906 "Call set_indexing_base( SpMatrixIndexingBase::Cpp ) first." );
910 BELFEM_ASSERT( tIndex < mNumNonZeros,
"tried to access zero value in writable mode( %lu, %lu )",
911 (
long unsigned int ) aRowIndex,
912 (
long unsigned int ) aColIndex );
914 return mValues[ tIndex ];
921 const index_t & aColIndex )
const
924 "operator() called while matrix is in Fortran indexing mode. "
925 "Call set_indexing_base( SpMatrixIndexingBase::Cpp ) first." );
929 if( tIndex < mNumNonZeros )
931 return mValues[ tIndex ];
#define BELFEM_ASSERT(aCheck,...)
Definition assert.hpp:244
Sparse matrix in CSR or CSC format.
Definition cl_SpMatrix.hpp:52
void fill(const real aValue)
write a specific value into all entries of the value container
Definition cl_SpMatrix.cpp:722
index_t n_cols() const
number of columns of this matrix
Definition cl_SpMatrix.hpp:669
bool have_coo_indices() const
Definition cl_SpMatrix.hpp:685
SpMatrix(const SpMatrix &)=delete
void set_indexing_base(const enum SpMatrixIndexingBase &aBasis)
change the indexing base
Definition cl_SpMatrix.cpp:814
void load(const string &aPath, const string aLabel="Matrix")
load matrix from a hdf5 file
Definition cl_SpMatrix.cpp:1248
index_t n_rows() const
number of rows of this matrix
Definition cl_SpMatrix.hpp:661
int_t * indices()
expose the index array
Definition cl_SpMatrix.hpp:701
real * data()
expose the data container
Definition cl_SpMatrix.hpp:787
void free_coo_indices()
delete additional indices that are needed by MUMPS
Definition cl_SpMatrix.cpp:1020
real & operator()(const index_t &aRowIndex, const index_t &aColIndex)
access a specific value with write access
Definition cl_SpMatrix.hpp:901
index_t n_pointers() const
Definition cl_SpMatrix.hpp:677
int_t * cols()
expose the col indices
Definition cl_SpMatrix.hpp:755
void set_type(const SpMatrixType aType)
sets the type, must be called after set_sizes
Definition cl_SpMatrix.cpp:1981
index_t number_of_nonzeros() const
number of nonzero values in this matrix
Definition cl_SpMatrix.hpp:693
void multiply(const Vector< real > &aX, Vector< real > &aY, const real aAlpha, const real aBeta, const bool aTransposedFlag=false)
performs a matrix-vector multiplication
Definition cl_SpMatrix.cpp:1617
int_t * pointers()
expose the pointers
Definition cl_SpMatrix.hpp:771
int_t indexing_base() const
returns the basis type of the matrix 0: c++ indexing 1: fortran indexing
Definition cl_SpMatrix.hpp:829
int_t index(const index_t aRowIndex, const index_t aColIndex) const
Definition cl_SpMatrix.hpp:890
void create_coo_indices()
create addidional indices that are needed by MUMPS
Definition cl_SpMatrix.cpp:902
size_t memory() const
Definition cl_SpMatrix.cpp:1991
void print(const string aLabel="SparseMatrix")
print_t the matrix to the screen ( for debugging )
Definition cl_SpMatrix.cpp:1094
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 s...
Definition cl_SpMatrix.cpp:1488
SpMatrix(SpMatrix &&)=delete
void print2(const string aLabel="SparseMatrix")
print_t the container indices on the screen ( for debugging )
Definition cl_SpMatrix.cpp:1133
SpMatrix & operator=(const SpMatrix &aMatrix)
copy operator
Definition cl_SpMatrix.cpp:1775
int_t * rows()
expose the row indices
Definition cl_SpMatrix.hpp:739
void transpose()
Definition cl_SpMatrix.cpp:1925
const SpMatrixType & type() const
return the data type
Definition cl_SpMatrix.hpp:653
void sort_entries()
Ensure that the indices within each row (CSR) or column (CSC) are sorted in ascending order.
Definition cl_SpMatrix.cpp:730
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...
Definition cl_SpMatrix.hpp:837
void save(const string &aPath, const string aLabel="Matrix", const enum FileMode aMode=FileMode::NEW)
save matrix to a hdf5 file
Definition cl_SpMatrix.cpp:1162
USER GUIDES:
Definition cl_Capacitor.cpp:16
Cell< graph::Vertex * > Graph
Definition cl_Graph_Vertex.hpp:329
int hid_t
Definition hdf5_types.hpp:20
SpMatrixType
Definition cl_SpMatrix.hpp:29
@ CSC
Definition cl_SpMatrix.hpp:30
@ CSR
Definition cl_SpMatrix.hpp:31
SpMatrixIndexingBase
Definition cl_SpMatrix.hpp:38
@ Fortran
Definition cl_SpMatrix.hpp:40
@ Cpp
Definition cl_SpMatrix.hpp:39
unsigned int uint
Definition typedefs.hpp:30
auto operator*(const Matrix< T > &aA, const Matrix< T > &aB) -> decltype(aA.matrix_data() *aB.matrix_data())
Definition op_MatrixTimes.hpp:24
FileMode
Definition filetools.hpp:27
@ NEW
Definition filetools.hpp:28
uint32_t index_t
Definition typedefs.hpp:52
int herr_t
Definition hdf5_types.hpp:21
double real
Definition typedefs.hpp:36
int32_t int_t
Definition typedefs.hpp:51