Sparse Matrix Manipulation in Libigl
Table of Contents:
Here I’ve compiled a list of functions to manipulate Eigen::SparseMatrix in Libigl, due to the lack of documentation.
Up-to-date with commit 1f5a0c1.
Creation
cat.h
Concatenate two SparseMatrix.
diag.h
Extract the diagonal entries of a SparseMatrix into a Vector and vice-versa. This is superceded by
VectorXd V = X.diagonal() and
SparseVector<double> V = X.diagonal().sparseView()
SparseMatrix<double> X = V.asDiagonal().sparseView()
invert_diag.h
Invert the diagonal entries of a SparseMatrix.
repdiag.h
Repeat a SparseMatrix on the diagonal n times to form a new SparseMatrix.
repmat.h
Repeat a SparseMatrix along the columns and rows to form a r by c SparseMatrix.
sparse.h
Create a SparseMatrix from indices and values. It’s a simple wrapper to the Eigen::SparseMatrix::setFromTriplets method.
sparse_cached.h
Faster version of sparse using cached data.
speye.h
Create a sparse identity matrix.
Predicate
is_sparse.h
Determine if a matrix is SparseMatrx.
is_symmetric.h
Determine if a SparseMatrix is symmetric.
is_diag.h
Determine if a SparseMatrix is diagonal.
Coefficient-wise Operation
for_each
Apply a function for each non-zero element. Could be replaced with Eigen::SparseMatrix::unaryExpr.
Note that Eigen::SparseMatrix also provides a lot of coefficient-wise operations to use.
Reduction and Visitor
all.h
Return true if all coefficients in a row/column of a SparseMatrix are true.
any.h
Return true if any coefficient in a row/column of a SparseMatrix is true.
count.h
Return the number of coefficients that are true in each row/column in a given SparseMatrix.
find.h
Get the values and indices of non-zero elements in a SparseMatrix. It’s a convinient wrapper to:
SparseMatrix<double> mat(rows,cols);
for (int k=0; k<mat.outerSize(); ++k)
for (SparseMatrix<double>::InnerIterator it(mat,k); it; ++it)
{
it.value();
it.row(); // row index
it.col(); // col index (here it is equal to k)
it.index(); // inner index, here it is equal to it.row()
}
find_zero.h
Return the first zero rows/columns of a SparseMatrix.
max.h
Return the values and indices of the maximum elements of each row/column in a SparseMatrix.
min.h
Return the values and indices of the minimum elements of each row/column in a SparseMatrix.
redux.h
Run a function to reduce the SparseMatrix colwise/rowwise.
sum.h
Return the colwise/rowwise sum of a SparseMatrix.
Slicing
slice.h
Slice a SparseMatrix into a sub-matrix.
slice_cached.h
Faster version of slice using cached data.
slice_into.h
Copy a SparseMatrix into a slice of another one.
slice_mask.h
Slice using mask instead of indices.
Decomposition
eigs.h
Eigen value decomposition. See Spectra for a more sophisticated solution.
Other Utilities
print_ijv.h
Print the indices and values of non-zero entries.