TBTK
Need a break? Support the development by playing Polarity Puzzles
TBTK::SparseMatrix< DataType > Class Template Reference

Public Types

enum  StorageFormat { CSR, CSC }
 

Public Member Functions

 SparseMatrix ()
 
 SparseMatrix (StorageFormat)
 
 SparseMatrix (const SparseMatrix &sparseMatrix)
 
 SparseMatrix (SparseMatrix &&sparseMatrix)
 
 SparseMatrix (StorageFormat storageFormat, unsigned int numRows, unsigned int numCols)
 
SparseMatrixoperator= (const SparseMatrix &sparseMatrix)
 
SparseMatrixoperator= (SparseMatrix &&sparseMatrix)
 
 ~SparseMatrix ()
 
void add (unsigned int row, unsigned int col, const DataType &value)
 
void setStorageFormat (StorageFormat storageFormat)
 
unsigned int getNumRows () const
 
unsigned int getNumColumns () const
 
unsigned int getCSRNumMatrixElements () const
 
unsigned int getCSCNumMatrixElements () const
 
const unsigned int * getCSRRowPointers () const
 
const unsigned int * getCSCColumnPointers () const
 
const unsigned int * getCSRColumns () const
 
const unsigned int * getCSCRows () const
 
const DataType * getCSRValues () const
 
const DataType * getCSCValues () const
 
void construct ()
 
SparseMatrixoperator+= (const SparseMatrix &rhs)
 
SparseMatrix operator+ (const SparseMatrix &rhs) const
 
SparseMatrixoperator-= (const SparseMatrix &rhs)
 
SparseMatrix operator- (const SparseMatrix &rhs) const
 
SparseMatrix operator* (const SparseMatrix &rhs) const
 
SparseMatrixoperator*= (const DataType &rhs)
 
SparseMatrix operator* (const DataType &rhs) const
 
SparseMatrix hermitianConjugate () const
 
DataType trace () const
 
void print () const
 
std::vector< std::vector< std::tuple< unsigned int, DataType > > > constructLIL ()
 
void sortLIL (std::vector< std::vector< std::tuple< unsigned int, DataType >> > &listOfLists) const
 
void mergeLIL (std::vector< std::vector< std::tuple< unsigned int, DataType >> > &listOfLists) const
 
void constructCSX ()
 
void convertCSXToLIL ()
 

Static Public Member Functions

static void multiply (const SparseMatrix &lhs, const SparseMatrix &rhs, SparseMatrix &result)
 

Friends

SparseMatrix operator* (const DataType &lhs, const SparseMatrix &rhs)
 

Member Enumeration Documentation

◆ StorageFormat

template<typename DataType >
enum TBTK::SparseMatrix::StorageFormat
strong

Enum class for determining the storage format.

Constructor & Destructor Documentation

◆ SparseMatrix() [1/5]

template<typename DataType >
TBTK::SparseMatrix< DataType >::SparseMatrix
inline

Constructor.

◆ SparseMatrix() [2/5]

template<typename DataType >
TBTK::SparseMatrix< DataType >::SparseMatrix ( StorageFormat  storageFormat)
inline

Constructor.

◆ SparseMatrix() [3/5]

template<typename DataType >
TBTK::SparseMatrix< DataType >::SparseMatrix ( const SparseMatrix< DataType > &  sparseMatrix)
inline

Copy constructor.

◆ SparseMatrix() [4/5]

template<typename DataType >
TBTK::SparseMatrix< DataType >::SparseMatrix ( SparseMatrix< DataType > &&  sparseMatrix)
inline

Copy constructor.

◆ SparseMatrix() [5/5]

template<typename DataType >
TBTK::SparseMatrix< DataType >::SparseMatrix ( StorageFormat  storageFormat,
unsigned int  numRows,
unsigned int  numCols 
)
inline

Constructor.

◆ ~SparseMatrix()

template<typename DataType >
TBTK::SparseMatrix< DataType >::~SparseMatrix
inline

Destructor.

Member Function Documentation

◆ add()

template<typename DataType >
void TBTK::SparseMatrix< DataType >::add ( unsigned int  row,
unsigned int  col,
const DataType &  value 
)
inline

Add matrix element.

◆ construct()

template<typename DataType >
void TBTK::SparseMatrix< DataType >::construct
inline

Construct the sparse matrix.

◆ constructCSX()

template<typename DataType >
void TBTK::SparseMatrix< DataType >::constructCSX
inline

Construct matrix on compressed sparse row format (CSR).

◆ constructLIL()

template<typename DataType >
std::vector< std::vector<std::tuple<unsigned int, DataType> > > TBTK::SparseMatrix< DataType >::constructLIL ( )

Construct list of lists (LIL) from dictionaryOfKeys.

◆ convertCSXToLIL()

template<typename DataType >
void TBTK::SparseMatrix< DataType >::convertCSXToLIL
inline

Adds all matrix elements constructed on CSR/CSC format to LIL. Used when a matrix is reconstructed either because new elements has been added, or because the format of the matrix is being changed.

◆ getCSCColumnPointers()

template<typename DataType >
const unsigned int * TBTK::SparseMatrix< DataType >::getCSCColumnPointers
inline

Get CSC column pointers.

◆ getCSCNumMatrixElements()

template<typename DataType >
unsigned int TBTK::SparseMatrix< DataType >::getCSCNumMatrixElements
inline

Get number of CSC matrix elements.

◆ getCSCRows()

template<typename DataType >
const unsigned int * TBTK::SparseMatrix< DataType >::getCSCRows
inline

Get CSC columns.

◆ getCSCValues()

template<typename DataType >
const DataType * TBTK::SparseMatrix< DataType >::getCSCValues
inline

Get CSC values.

◆ getCSRColumns()

template<typename DataType >
const unsigned int * TBTK::SparseMatrix< DataType >::getCSRColumns
inline

Get CSR columns.

◆ getCSRNumMatrixElements()

template<typename DataType >
unsigned int TBTK::SparseMatrix< DataType >::getCSRNumMatrixElements
inline

Get number of CSR matrix elements.

◆ getCSRRowPointers()

template<typename DataType >
const unsigned int * TBTK::SparseMatrix< DataType >::getCSRRowPointers
inline

Get CSR row pointers.

◆ getCSRValues()

template<typename DataType >
const DataType * TBTK::SparseMatrix< DataType >::getCSRValues
inline

Get CSR values.

◆ getNumColumns()

template<typename DataType >
unsigned int TBTK::SparseMatrix< DataType >::getNumColumns
inline

Get number of columns.

◆ getNumRows()

template<typename DataType >
unsigned int TBTK::SparseMatrix< DataType >::getNumRows
inline

Get number of rows.

◆ hermitianConjugate()

template<typename DataType >
SparseMatrix< DataType > TBTK::SparseMatrix< DataType >::hermitianConjugate
inline

Calculate the Hermitian conjugate of the matrix.

Returns
A new matrix containing the Hermitian cojugate of the matrix.

◆ mergeLIL()

template<typename DataType >
void TBTK::SparseMatrix< DataType >::mergeLIL ( std::vector< std::vector< std::tuple< unsigned int, DataType >> > &  listOfLists) const
inline

Merge list of lists (LIL) entries with the same row and column indices.

◆ multiply()

template<typename DataType >
void TBTK::SparseMatrix< DataType >::multiply ( const SparseMatrix< DataType > &  lhs,
const SparseMatrix< DataType > &  rhs,
SparseMatrix< DataType > &  result 
)
inlinestatic

Helper function for operator*() that performs the actual matrix multiplication.

Parameters
rhsThe left hand side in the matrix multiplication.
rhsThe right hand side in the matrix multiplication.
resultThe SparseMatrix to store the result in.

◆ operator*() [1/2]

template<typename DataType >
SparseMatrix< DataType > TBTK::SparseMatrix< DataType >::operator* ( const DataType &  rhs) const
inline

Multiplication operator.

Parameters
rhsThe right hand side of the expression.
Returns
A new SparseMatrix that is the product of this SparseMatrix and the right hand side.

◆ operator*() [2/2]

template<typename DataType >
SparseMatrix< DataType > TBTK::SparseMatrix< DataType >::operator* ( const SparseMatrix< DataType > &  rhs) const
inline

Multiplication operator.

Parameters
rhsThe right hand side of the expression.
Returns
A new SparseMatrix that is the product of this SparseMatrix and the right hand side.

◆ operator*=()

template<typename DataType >
SparseMatrix< DataType > & TBTK::SparseMatrix< DataType >::operator*= ( const DataType &  rhs)
inline

Multiplication assignment operator.

Parameters
rhsThe right hand side of the expression.
Returns
The left hand side after the right hand side has been multiplied in.

◆ operator+()

template<typename DataType >
SparseMatrix< DataType > TBTK::SparseMatrix< DataType >::operator+ ( const SparseMatrix< DataType > &  rhs) const
inline

Addition operator.

Parameters
rhsThe right hand side of the expression.
Returns
A new SparseMatrix that is the sum of this SparseMatrix and the right hand side.

◆ operator+=()

template<typename DataType >
SparseMatrix< DataType > & TBTK::SparseMatrix< DataType >::operator+= ( const SparseMatrix< DataType > &  rhs)
inline

Addition assignment operator.

Parameters
rhsThe right hand side of the expression.
Returns
The left hand side after the right hand side has been added.

◆ operator-()

template<typename DataType >
SparseMatrix< DataType > TBTK::SparseMatrix< DataType >::operator- ( const SparseMatrix< DataType > &  rhs) const
inline

Subtraction operator.

Parameters
rhsThe right hand side of the expression.
Returns
A new SparseMatrix that is the difference between this SparseMatrix and the right hand side.

◆ operator-=()

template<typename DataType >
SparseMatrix< DataType > & TBTK::SparseMatrix< DataType >::operator-= ( const SparseMatrix< DataType > &  rhs)
inline

Subtraction assignment operator.

Parameters
rhsThe right hand side of the expression.
Returns
The left hand side after the right hand side has been subtracted.

◆ operator=() [1/2]

template<typename DataType >
SparseMatrix< DataType > & TBTK::SparseMatrix< DataType >::operator= ( const SparseMatrix< DataType > &  sparseMatrix)
inline

Assignment operator.

◆ operator=() [2/2]

template<typename DataType >
SparseMatrix< DataType > & TBTK::SparseMatrix< DataType >::operator= ( SparseMatrix< DataType > &&  sparseMatrix)
inline

Move assignment operator.

◆ print()

template<typename DataType >
void TBTK::SparseMatrix< DataType >::print
inline

Print.

◆ setStorageFormat()

template<typename DataType >
void TBTK::SparseMatrix< DataType >::setStorageFormat ( StorageFormat  storageFormat)
inline

Set StorageFormat.

◆ sortLIL()

template<typename DataType >
void TBTK::SparseMatrix< DataType >::sortLIL ( std::vector< std::vector< std::tuple< unsigned int, DataType >> > &  listOfLists) const
inline

Sort list of lists (LIL).

◆ trace()

template<typename DataType >
DataType TBTK::SparseMatrix< DataType >::trace
inline

Calculate the trace.

Returns
The trace of the matrix.

Friends And Related Function Documentation

◆ operator*

template<typename DataType >
SparseMatrix operator* ( const DataType &  lhs,
const SparseMatrix< DataType > &  rhs 
)
friend

Multiplication operator.

Parameters
lhsThe left hand side of the expression.
rhsThe right hand side of the expression.
Returns
A new SparseMatrix that is the product of the left and right hand side.

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