IVSparse  v1.0
A sparse matrix compression library.
SparseMatrix< T, indexT, 2, columnMajor >

Inherits SparseMatrixBase.

Classes

class  Vector
 

Constructors

 SparseMatrix ()
 
 SparseMatrix (Eigen::SparseMatrix< T > &mat)
 
 SparseMatrix (Eigen::SparseMatrix< T, Eigen::RowMajor > &mat)
 
template<uint8_t compressionLevel2>
 SparseMatrix (IVSparse::SparseMatrix< T, indexT, compressionLevel2, columnMajor > &other)
 
 SparseMatrix (const IVSparse::SparseMatrix< T, indexT, 2, columnMajor > &other)
 
template<typename T2 , typename indexT2 >
 SparseMatrix (T2 *vals, indexT2 *innerIndices, indexT2 *outerPtr, uint32_t num_rows, uint32_t num_cols, uint32_t nnz)
 
template<typename T2 , typename indexT2 >
 SparseMatrix (std::vector< std::tuple< indexT2, indexT2, T2 >> &entries, uint32_t num_rows, uint32_t num_cols, uint32_t nnz)
 
 SparseMatrix (typename IVSparse::SparseMatrix< T, indexT, 2, columnMajor >::Vector &vec)
 
 SparseMatrix (std::vector< typename IVSparse::SparseMatrix< T, indexT, 2, columnMajor >::Vector > &vecs)
 
 SparseMatrix (const char *filename)
 
 ~SparseMatrix ()
 

Getters

coeff (uint32_t row, uint32_t col)
 
bool isColumnMajor () const
 
T * getValues (uint32_t vec) const
 
indexT * getCounts (uint32_t vec) const
 
indexT * getIndices (uint32_t vec) const
 
indexT getNumUniqueVals (uint32_t vec) const
 
indexT getNumIndices (uint32_t vec) const
 
IVSparse::SparseMatrix< T, indexT, 2, columnMajor >::Vector getVector (uint32_t vec)
 

Calculations

std::vector< T > outerSum ()
 
std::vector< T > innerSum ()
 
std::vector< T > maxColCoeff ()
 
std::vector< T > maxRowCoeff ()
 
std::vector< T > minColCoeff ()
 
std::vector< T > minRowCoeff ()
 
trace ()
 
sum ()
 
double norm ()
 
double vectorLength (uint32_t vec)
 

Utility Methods

void write (const char *filename)
 
void print ()
 
IVSparse::SparseMatrix< T, indexT, 1, columnMajor > toCSC ()
 
IVSparse::SparseMatrix< T, indexT, 3, columnMajor > toIVCSC ()
 
Eigen::SparseMatrix< T, columnMajor ? Eigen::ColMajor :Eigen::RowMajor > toEigen ()
 

Matrix Manipulation Methods

IVSparse::SparseMatrix< T, indexT, 2, columnMajor > transpose ()
 
void inPlaceTranspose ()
 
void append (typename SparseMatrix< T, indexT, 2, columnMajor >::Vector &vec)
 
std::vector< typename IVSparse::SparseMatrix< T, indexT, 2, columnMajor >::Vector > slice (uint32_t start, uint32_t end)
 

Additional Inherited Members

- Public Member Functions inherited from SparseMatrixBase
template<typename T >
coeff (uint32_t row, uint32_t col)
 
uint32_t rows () const
 
uint32_t cols () const
 
uint32_t innerSize () const
 
uint32_t outerSize () const
 
uint32_t nonZeros () const
 
size_t byteSize () const
 

Detailed Description

template<typename T, typename indexT, bool columnMajor>
class IVSparse::SparseMatrix< T, indexT, 2, columnMajor >

The VCSC Sparse Matrix Class is a version of the CSC format. The difference is that CSC is base CSC but VCSC is CSC with run length encoding and a vector that keeps track of the number of occurances of a value in a column. This allows for fast level 1 BLAS operations and still compresses more with redundant data than CSC.

Constructor & Destructor Documentation

◆ SparseMatrix() [1/10]

SparseMatrix ( )
inline

Construct an empty IVSparse matrix

The matrix will have 0 rows and 0 columns and will not be initialized with any values. All data will be set to nullptr.

Attention
This constructor is not recommended for use as updating a IVSparse matrix is not well supported.

◆ SparseMatrix() [2/10]

SparseMatrix ( Eigen::SparseMatrix< T > &  mat)
Parameters
matThe Eigen Sparse Matrix to be compressed

Eigen Sparse Matrix Constructor

This constructor takes an Eigen Sparse Matrix and compresses it into a IVSparse matrix.

◆ SparseMatrix() [3/10]

SparseMatrix ( Eigen::SparseMatrix< T, Eigen::RowMajor > &  mat)
Parameters
matThe Eigen Sparse Matrix to be compressed

Eigen Sparse Matrix Constructor (Row Major)

Same as previous constructor but for Row Major Eigen Sparse Matrices.

◆ SparseMatrix() [4/10]

SparseMatrix ( IVSparse::SparseMatrix< T, indexT, compressionLevel2, columnMajor > &  other)
Template Parameters
compressionLevel2The compression level of the IVSparse matrix to convert
Parameters
matThe IVSparse matrix to convert

Convert a IVSparse matrix of a different compression level to this compression level.

This constructor takes in a IVSparse matrix of the same storage order, value, and index type and converts it to a different compresion level. This is useful for converting between compression levels without having to go through the CSC format.

◆ SparseMatrix() [5/10]

SparseMatrix ( const IVSparse::SparseMatrix< T, indexT, 2, columnMajor > &  other)
Parameters
otherThe IVSparse matrix to be copied

Deep Copy Constructor

This constructor takes in a VCSC matrix and creates a deep copy of it.

◆ SparseMatrix() [6/10]

SparseMatrix ( T2 *  vals,
indexT2 *  innerIndices,
indexT2 *  outerPtr,
uint32_t  num_rows,
uint32_t  num_cols,
uint32_t  nnz 
)

Raw CSC Constructor

This constructor takes in raw CSC storage format pointers and converts it to a VCSC matrix. One could also take this information and convert to an Eigen Sparse Matrix and then to a VCSC matrix.

◆ SparseMatrix() [7/10]

SparseMatrix ( std::vector< std::tuple< indexT2, indexT2, T2 >> &  entries,
uint32_t  num_rows,
uint32_t  num_cols,
uint32_t  nnz 
)

COO Tuples Constructor

This constructor takes in a list of tuples in COO format which can be unsorted but without duplicates. The tuples are sorted and then converted to a IVSparse matrix.

Note
COO is (row, col, value) format.

◆ SparseMatrix() [8/10]

SparseMatrix ( typename IVSparse::SparseMatrix< T, indexT, 2, columnMajor >::Vector &  vec)
Parameters
vecThe vector to construct the matrix from

IVSparse Vector Constructor

This constructor takes in a single VCSC vector and creates a one column/row VCSC matrix.

◆ SparseMatrix() [9/10]

SparseMatrix ( std::vector< typename IVSparse::SparseMatrix< T, indexT, 2, columnMajor >::Vector > &  vecs)
Parameters
vecsThe vector of VCSC vectors to construct from.

Vector of IVSparse Vectors Constructor

This constructor takes in an vector of VCSC vectors and creates a VCSC matrix from them.

◆ SparseMatrix() [10/10]

SparseMatrix ( const char *  filename)
Parameters
filenameThe filepath of the matrix to be read in

File Constructor

Given a filepath to a VCSC matrix written to file this constructor will read in the matrix and construct it.

Member Function Documentation

◆ coeff()

T coeff ( uint32_t  row,
uint32_t  col 
)
Returns
T The value at the specified row and column. Returns 0 if the value is not found.

Get the value at the specified row and column

Note
Users cannot update individual values in a IVSparse matrix.
Warning
This method is not efficient and should not be used in performance critical code.

◆ isColumnMajor()

bool isColumnMajor
Returns
true If the matrix is stored in column major format
false If the matrix is stored in row major format

See the storage order of the IVSparse matrix.

◆ getValues()

T * getValues ( uint32_t  vec) const
Parameters
vecThe vector to get the values for
Returns
A pointer to the values of a given vector in a VCSC Matrix

◆ getCounts()

indexT * getCounts ( uint32_t  vec) const
Parameters
vecThe vector to get the counts for
Returns
A pointer to the value counts of a given vector in a VCSC Matrix

◆ getIndices()

indexT * getIndices ( uint32_t  vec) const
Parameters
vecThe vector to get the indices for
Returns
A pointer to the indices of a given vector in a VCSC Matrix

◆ getNumUniqueVals()

indexT getNumUniqueVals ( uint32_t  vec) const
Parameters
vecThe vector to get the unique values for
Returns
The number of unique values in a given vector in a VCSC Matrix

◆ getNumIndices()

indexT getNumIndices ( uint32_t  vec) const
Parameters
vecThe vector to get the the number of indices for
Returns
The number of indices (nonzeros) in a given vector in a VCSC Matrix

◆ getVector()

IVSparse::SparseMatrix< T, indexT, 2, columnMajor >::Vector getVector ( uint32_t  vec)
Parameters
vecThe vector to get a copy of
Returns
Vector The vector copy returned

Get a copy of a IVSparse vector from the IVSparse matrix such as the first column.

Note
Can only get vectors in the storage order of the matrix.

◆ outerSum()

std::vector< T > outerSum
inline
Returns
A vector of the sum of each vector along the outer dimension.

◆ innerSum()

std::vector< T > innerSum
inline
Returns
A vector of the sum of each vector along the inner dimension.

◆ maxColCoeff()

std::vector< T > maxColCoeff
inline
Returns
A vector of the maximum value in each column.

◆ maxRowCoeff()

std::vector< T > maxRowCoeff
inline
Returns
A vector of the maximum value in each row.

◆ minColCoeff()

std::vector< T > minColCoeff
inline
Returns
A vector of the minimum value in each column.

◆ minRowCoeff()

std::vector< T > minRowCoeff
inline
Returns
A vector of the minimum value in each row.

◆ trace()

T trace
inline
Returns
The trace of the matrix.
Note
Only works for square matrices.

◆ sum()

T sum
inline
Returns
The sum of all the values in the matrix.

◆ norm()

double norm
inline
Returns
The frobenius norm of the matrix.

◆ vectorLength()

double vectorLength ( uint32_t  vec)
inline
Returns
Returns the length of the specified vector.

◆ write()

void write ( const char *  filename)
virtual
Parameters
filenameThe filename of the matrix to write to

This method writes the IVSparse matrix to a file in binary format. This can then be read in later using the file constructor. Currently .csf is the perfered file extension.

Note
Useful to split a matrix up and then write each part separately.

Implements SparseMatrixBase.

◆ print()

void print
virtual

Prints "IVSparse Matrix:" followed by the dense representation of the matrix to the console.

Note
Useful for debugging but only goes up to 100 of either dimension.

Implements SparseMatrixBase.

◆ toCSC()

IVSparse::SparseMatrix< T, indexT, 1, columnMajor > toCSC
Returns
The current matrix as uncompressed to CSC format.

◆ toIVCSC()

IVSparse::SparseMatrix< T, indexT, 3, columnMajor > toIVCSC
Returns
The current matrix as a IVCSC Matrix.

◆ toEigen()

Eigen::SparseMatrix< T, columnMajor ? Eigen::ColMajor :Eigen::RowMajor > toEigen
Returns
An Eigen Sparse Matrix constructed from the VCSC matrix data.

◆ transpose()

IVSparse::SparseMatrix< T, indexT, 2, columnMajor > transpose
Returns
A transposed version of the IVSparse matrix.
Warning
This method is not very efficient for VCSC and IVCSC matrices.

◆ inPlaceTranspose()

void inPlaceTranspose

Transposes the matrix in place instead of returning a new matrix.

Warning
This method is not very efficient for VCSC and IVCSC matrices.

◆ append()

void append ( typename SparseMatrix< T, indexT, 2, columnMajor >::Vector &  vec)
Parameters
vecThe vector to append to the matrix in the correct storage order.

Appends a IVSparse vector to the current matrix in the storage order of the matrix.

◆ slice()

std::vector< typename IVSparse::SparseMatrix< T, indexT, 2, columnMajor >::Vector > slice ( uint32_t  start,
uint32_t  end 
)
Returns
A vector of IVSparse vectors that represent a slice of the IVSparse matrix.