Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
SparseMatrix.h File Reference
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <stdexcept>
Include dependency graph for SparseMatrix.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  SparseMatrixWrapper< T >
 

Typedefs

template<typename T >
using SparseMatrix = std::map< std::pair< T, T >, double >
 Alias for a sparse matrix using a map of coordinate pairs.
 

Functions

template<typename T >
std::vector< TgetDiagonalElements (const SparseMatrix< T > &matrix)
 Extracts the diagonal elements from a sparse matrix.
 
template<typename T >
SparseMatrix< TcreateIdentityMatrix (const std::vector< T > &indices)
 Creates an identity matrix from a list of indices.
 
template<typename T >
double getElement (const SparseMatrix< T > &matrix, const T &row, const T &col)
 Retrieves an element from the sparse matrix.
 
template<typename T >
void setElement (SparseMatrix< T > &matrix, const T &row, const T &col, double value)
 Sets or updates an element in the sparse matrix.
 
template<typename T >
SparseMatrix< TinvertMatrix (const SparseMatrix< T > &matrix, const std::vector< T > &indices)
 Inverts a square sparse matrix using Gauss-Jordan elimination.
 
template<typename T >
std::pair< SparseMatrix< T >, std::vector< T > > removeEmptyRowsAndCols (const SparseMatrix< T > &matrix, const std::vector< T > &indices)
 Removes rows and columns that are entirely zero (i.e., not present in the sparse matrix).
 
template<typename T >
void printMatrix (const SparseMatrix< T > &matrix, const std::vector< T > &indices)
 Prints the matrix in dense form using a list of indices.
 
template<typename T >
void customPrintMatrix (const SparseMatrix< T > &matrix, const std::vector< T > &indices)
 Prints the matrix in a formatted grid with row and column headers.
 

Typedef Documentation

◆ SparseMatrix

template<typename T >
using SparseMatrix = std::map<std::pair<T, T>, double>

Alias for a sparse matrix using a map of coordinate pairs.

Template Parameters
TType of the row and column indices.

Definition at line 16 of file SparseMatrix.h.

Function Documentation

◆ createIdentityMatrix()

template<typename T >
SparseMatrix< T > createIdentityMatrix ( const std::vector< T > &  indices)

Creates an identity matrix from a list of indices.

Template Parameters
TIndex type.
Parameters
indicesList of row/column indices.
Returns
Sparse identity matrix.

Definition at line 44 of file SparseMatrix.h.

◆ customPrintMatrix()

template<typename T >
void customPrintMatrix ( const SparseMatrix< T > &  matrix,
const std::vector< T > &  indices 
)

Prints the matrix in a formatted grid with row and column headers.

Template Parameters
TIndex type (must support std::ostream << operator).
Parameters
matrixSparse matrix.
indicesList of row/column indices.

Definition at line 206 of file SparseMatrix.h.

◆ getDiagonalElements()

template<typename T >
std::vector< T > getDiagonalElements ( const SparseMatrix< T > &  matrix)

Extracts the diagonal elements from a sparse matrix.

Template Parameters
TIndex type.
Parameters
matrixThe sparse matrix.
Returns
Vector of diagonal indices.

Definition at line 26 of file SparseMatrix.h.

◆ getElement()

template<typename T >
double getElement ( const SparseMatrix< T > &  matrix,
const T row,
const T col 
)

Retrieves an element from the sparse matrix.

Template Parameters
TIndex type.
Parameters
matrixThe sparse matrix.
rowRow index.
colColumn index.
Returns
Value of the element (0.0 if not present).

Definition at line 62 of file SparseMatrix.h.

◆ invertMatrix()

template<typename T >
SparseMatrix< T > invertMatrix ( const SparseMatrix< T > &  matrix,
const std::vector< T > &  indices 
)

Inverts a square sparse matrix using Gauss-Jordan elimination.

Template Parameters
TIndex type.
Parameters
matrixInput square sparse matrix.
indicesList of row/column indices (must match matrix size).
Returns
Inverted matrix.
Exceptions
std::runtime_errorif the matrix is singular.

Definition at line 98 of file SparseMatrix.h.

◆ printMatrix()

template<typename T >
void printMatrix ( const SparseMatrix< T > &  matrix,
const std::vector< T > &  indices 
)

Prints the matrix in dense form using a list of indices.

Template Parameters
TIndex type.
Parameters
matrixSparse matrix.
indicesList of indices to determine order.

Definition at line 189 of file SparseMatrix.h.

◆ removeEmptyRowsAndCols()

template<typename T >
std::pair< SparseMatrix< T >, std::vector< T > > removeEmptyRowsAndCols ( const SparseMatrix< T > &  matrix,
const std::vector< T > &  indices 
)

Removes rows and columns that are entirely zero (i.e., not present in the sparse matrix).

Template Parameters
TIndex type.
Parameters
matrixThe input sparse matrix.
indicesThe input list of row/column indices.
Returns
A pair containing:
  • The cleaned sparse matrix.
  • The updated list of indices.

Definition at line 142 of file SparseMatrix.h.

◆ setElement()

template<typename T >
void setElement ( SparseMatrix< T > &  matrix,
const T row,
const T col,
double  value 
)

Sets or updates an element in the sparse matrix.

Template Parameters
TIndex type.
Parameters
matrixSparse matrix to modify.
rowRow index.
colColumn index.
valueValue to assign.

Definition at line 80 of file SparseMatrix.h.