SparseStorageFormats

#include <popsparse/SparseStorageFormats.hpp>

Storage formats for a block sparse matrix.

namespace popsparse

Support for sparse matrices.

struct Block

Subclassed by popsparse::COOMatrix< T >, popsparse::CSCMatrix< T >, popsparse::CSRMatrix< T >

Public Functions

inline std::size_t getNumColumnsInBlock() const
inline std::size_t getNumRowsInBlock() const
inline std::size_t getBlockSize() const
inline std::array<std::size_t, 2> getBlockDimensions() const

Protected Attributes

std::array<std::size_t, 2> blockDimensions
template<typename T>
struct COOMatrix : public popsparse::Block
#include <SparseStorageFormats.hpp>

Block Sparse matrix stored as coordinate (COO) or triplets format.

The case of element sparsity is treated as a special case with block size equal to {number of rows in block, number of columns in block} = {1, 1}.

Public Functions

inline COOMatrix(const std::vector<T> &nzValues, const std::vector<std::size_t> &columnIndices, const std::vector<std::size_t> &rowIndices, const std::array<std::size_t, 2> &blockDimensions = {1, 1})
inline COOMatrix(std::size_t numRows, std::size_t numColumns, const std::vector<T> &nzValues, const std::vector<std::size_t> &columnIndices, const std::vector<std::size_t> &rowIndices, const std::array<std::size_t, 2> &blockDimensions = {1, 1})
inline COOMatrix(std::vector<T> &&nzValues, std::vector<std::size_t> &&columnIndices, std::vector<std::size_t> &&rowIndices, const std::array<std::size_t, 2> &blockDimensions = {1, 1})
inline COOMatrix(std::size_t numRows, std::size_t numColumns, std::vector<T> &&nzValues, std::vector<std::size_t> &&columnIndices, std::vector<std::size_t> &&rowIndices, const std::array<std::size_t, 2> &blockDimensions = {1, 1})
inline COOMatrix(std::size_t numNZValues, const std::array<std::size_t, 2> &blockDimensions_ = {1, 1})

Constructor to allocate memory.

inline COOMatrix(const std::array<std::size_t, 2> &blockDimensions = {1, 1})
COOMatrix(const COOMatrix&) = default

Public Members

std::size_t numRows = 0

Number of rows in the dense matrix the COO represents.

std::size_t numColumns = 0

Number of columns in the dense matrix the COO represents.

std::vector<T> nzValues

The non-zero values of the sparse matrix.

std::vector<std::size_t> columnIndices

Corresponding column indices for the non-zero values.

std::vector<std::size_t> rowIndices

Corresponding row indices for the non-zero values.

template<typename T>
struct CSCMatrix : public popsparse::Block
#include <SparseStorageFormats.hpp>

Sparse matrix stored in compressed sparse columns (CSC) format for a matrix of size [M x N].

There is no explicit encoding of M in the storage. The number of column indices is equal to (N/number of columns in block) + 1. The case of element sparsity is treated as a special case with block size equal to {number of rows in block, number of columns in block} = {1, 1}.

Public Functions

inline CSCMatrix(const std::vector<T> &nzValues, const std::vector<std::size_t> &columnIndices, const std::vector<std::size_t> &rowIndices, const std::array<std::size_t, 2> &blockDimensions = {1, 1})
inline CSCMatrix(std::size_t numRows, std::size_t numColumns, const std::vector<T> &nzValues, const std::vector<std::size_t> &columnIndices, const std::vector<std::size_t> &rowIndices, const std::array<std::size_t, 2> &blockDimensions = {1, 1})
inline CSCMatrix(std::vector<T> &&nzValues, std::vector<std::size_t> &&columnIndices, std::vector<std::size_t> &&rowIndices, const std::array<std::size_t, 2> &blockDimensions = {1, 1})
inline CSCMatrix(std::size_t numRows, std::size_t numColumns, std::vector<T> &&nzValues, std::vector<std::size_t> &&columnIndices, std::vector<std::size_t> &&rowIndices, const std::array<std::size_t, 2> &blockDimensions = {1, 1})
inline CSCMatrix(std::size_t numNZValues, std::size_t numColumns, const std::array<std::size_t, 2> &blockDimensions_ = {1, 1})

Constructor to allocate memory.

inline CSCMatrix(const std::array<std::size_t, 2> &blockDimensions_ = {1, 1})
CSCMatrix(const CSCMatrix&) = default

Public Members

std::size_t numRows = 0

Number of rows in the dense matrix the CSC represents.

std::size_t numColumns = 0

Number of columns in the dense matrix the CSC represents.

std::vector<T> nzValues

The non-zero values of the sparse matrix.

The number of values is always an integer multiple of the block size.

std::vector<std::size_t> columnIndices

Indices where non-zero values for each column block starts.

There are a total of N/block size + 1 entries with the last entry equal to nzValues.

std::vector<std::size_t> rowIndices

The row index of each block in nzValues.

There are as many entries as the number of blocks in nzValues.

template<typename T>
struct CSRMatrix : public popsparse::Block
#include <SparseStorageFormats.hpp>

Sparse matrix stored in compressed sparse rows (CSR) format for a matrix of size [M x N].

There is no explicit encoding of N in the storage. The number of row indices is equal to (M / number of rows in block) + 1. The case of element sparsity is treated as a special case with block size equal to {number of rows in block, number of columns in block} = {1, 1}.

Public Functions

inline CSRMatrix(const std::vector<T> &nzValues, const std::vector<std::size_t> &columnIndices, const std::vector<std::size_t> &rowIndices, const std::array<std::size_t, 2> &blockDimensions = {1, 1})
inline CSRMatrix(std::size_t numRows, std::size_t numColumns, const std::vector<T> &nzValues, const std::vector<std::size_t> &columnIndices, const std::vector<std::size_t> &rowIndices, const std::array<std::size_t, 2> &blockDimensions = {1, 1})
inline CSRMatrix(std::vector<T> &&nzValues, std::vector<std::size_t> &&columnIndices, std::vector<std::size_t> &&rowIndices, const std::array<std::size_t, 2> &blockDimensions = {1, 1})
inline CSRMatrix(std::size_t numRows, std::size_t numColumns, std::vector<T> &&nzValues, std::vector<std::size_t> &&columnIndices, std::vector<std::size_t> &&rowIndices, const std::array<std::size_t, 2> &blockDimensions = {1, 1})
inline CSRMatrix(std::size_t numNZValues, std::size_t numRows, const std::array<std::size_t, 2> &blockDimensions_ = {1, 1})
inline CSRMatrix(const std::array<std::size_t, 2> &blockDimensions_ = {1, 1})
CSRMatrix(const CSRMatrix&) = default

Public Members

std::size_t numRows = 0

Number of rows in the dense matrix the CSR represents.

std::size_t numColumns = 0

Number of columns in the dense matrix the CSR represents.

std::vector<T> nzValues

The non-zero values of the sparse matrix.

std::vector<std::size_t> columnIndices

The column index of each block in nzValues.

There are as many as blocks in nzValues.

std::vector<std::size_t> rowIndices

Indices where non-zero blocks of each row start.

There are a total of M+1 entries with the last entry equal to the number of entries in nzValues.