MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
Loading...
Searching...
No Matches
mtl::sparse::util Namespace Reference

Namespaces

namespace  detail

Classes

struct  csc_matrix
 Lightweight CSC (Compressed Sparse Column) representation. More...
class  sparse_accumulator
 Sparse accumulator for assembling a sparse column. More...

Functions

template<typename Value, typename Parameters>
csc_matrix< Value, typename mat::compressed2D< Value, Parameters >::size_type > csr_to_csc (const mat::compressed2D< Value, Parameters > &A)
 Convert a CSR compressed2D matrix to CSC format.
template<typename Value, typename SizeType>
mat::compressed2D< Value > csc_to_csr (const csc_matrix< Value, SizeType > &csc)
 Convert a CSC matrix back to CSR compressed2D format.
template<typename Value, typename Parameters>
csc_matrix< Value, typename mat::compressed2D< Value, Parameters >::size_type > crs_to_csc (const mat::compressed2D< Value, Parameters > &A)
 Deprecated name of csr_to_csc (#1006: MTL5 writes CSR and CSC, not CRS).
template<typename Value, typename SizeType>
mat::compressed2D< Value > csc_to_crs (const csc_matrix< Value, SizeType > &csc)
 Deprecated name of csc_to_csr (#1006).
template<typename Value, typename SizeType>
csc_matrix< Value, SizeType > transpose_csc (const csc_matrix< Value, SizeType > &A)
 Compute the transpose of a CSC matrix (returns CSC).
std::vector< std::size_t > invert_permutation (const std::vector< std::size_t > &p)
 Compute the inverse of a permutation vector.
std::vector< std::size_t > identity_permutation (std::size_t n)
 Return the identity permutation of size n: p[i] = i.
std::vector< std::size_t > compose_permutations (const std::vector< std::size_t > &a, const std::vector< std::size_t > &b)
 Compose two permutations: result[i] = a[b[i]].
bool is_valid_permutation (const std::vector< std::size_t > &p)
 Check if a vector is a valid permutation of [0, n).
template<typename Value, typename Parameters>
mat::compressed2D< Value, Parameters > symmetric_permute (const mat::compressed2D< Value, Parameters > &A, const std::vector< std::size_t > &perm)
 Apply a symmetric permutation to a sparse matrix: B = P * A * P^T where P is the permutation matrix corresponding to perm.
template<typename Value, typename Parameters>
mat::compressed2D< Value, Parameters > column_permute (const mat::compressed2D< Value, Parameters > &A, const std::vector< std::size_t > &perm)
 Apply a column permutation to a sparse matrix: B = A * P^T so B(:, j) = A(:, perm[j]).
template<typename Value, typename Parameters>
mat::compressed2D< Value, Parameters > row_permute (const mat::compressed2D< Value, Parameters > &A, const std::vector< std::size_t > &perm)
 Apply a row permutation to a sparse matrix: B = P * A so B(pinv[old_row], :) = A(old_row, :).
template<typename Value>
std::vector< Value > permute_vector (const std::vector< Value > &x, const std::vector< std::size_t > &perm)
 Apply a permutation to a dense vector: y[i] = x[perm[i]].
template<typename Value>
std::vector< Value > ipermute_vector (const std::vector< Value > &x, const std::vector< std::size_t > &perm)
 Apply inverse permutation to a dense vector: y[perm[i]] = x[i].

Function Documentation

◆ column_permute()

template<typename Value, typename Parameters>
mat::compressed2D< Value, Parameters > mtl::sparse::util::column_permute ( const mat::compressed2D< Value, Parameters > & A,
const std::vector< std::size_t > & perm )

Apply a column permutation to a sparse matrix: B = A * P^T so B(:, j) = A(:, perm[j]).

Equivalently, B(i, pinv[old_col]) = A(i, old_col).

◆ compose_permutations()

std::vector< std::size_t > mtl::sparse::util::compose_permutations ( const std::vector< std::size_t > & a,
const std::vector< std::size_t > & b )
inline

Compose two permutations: result[i] = a[b[i]].

◆ crs_to_csc()

template<typename Value, typename Parameters>
csc_matrix< Value, typename mat::compressed2D< Value, Parameters >::size_type > mtl::sparse::util::crs_to_csc ( const mat::compressed2D< Value, Parameters > & A)

Deprecated name of csr_to_csc (#1006: MTL5 writes CSR and CSC, not CRS).

◆ csc_to_crs()

template<typename Value, typename SizeType>
mat::compressed2D< Value > mtl::sparse::util::csc_to_crs ( const csc_matrix< Value, SizeType > & csc)

Deprecated name of csc_to_csr (#1006).

◆ csc_to_csr()

template<typename Value, typename SizeType>
mat::compressed2D< Value > mtl::sparse::util::csc_to_csr ( const csc_matrix< Value, SizeType > & csc)

Convert a CSC matrix back to CSR compressed2D format.

◆ csr_to_csc()

template<typename Value, typename Parameters>
csc_matrix< Value, typename mat::compressed2D< Value, Parameters >::size_type > mtl::sparse::util::csr_to_csc ( const mat::compressed2D< Value, Parameters > & A)

Convert a CSR compressed2D matrix to CSC format.

◆ identity_permutation()

std::vector< std::size_t > mtl::sparse::util::identity_permutation ( std::size_t n)
inline

Return the identity permutation of size n: p[i] = i.

◆ invert_permutation()

std::vector< std::size_t > mtl::sparse::util::invert_permutation ( const std::vector< std::size_t > & p)
inline

Compute the inverse of a permutation vector.

Given p where p[new] = old, returns pinv where pinv[old] = new.

◆ ipermute_vector()

template<typename Value>
std::vector< Value > mtl::sparse::util::ipermute_vector ( const std::vector< Value > & x,
const std::vector< std::size_t > & perm )

Apply inverse permutation to a dense vector: y[perm[i]] = x[i].

◆ is_valid_permutation()

bool mtl::sparse::util::is_valid_permutation ( const std::vector< std::size_t > & p)
inline

Check if a vector is a valid permutation of [0, n).

◆ permute_vector()

template<typename Value>
std::vector< Value > mtl::sparse::util::permute_vector ( const std::vector< Value > & x,
const std::vector< std::size_t > & perm )

Apply a permutation to a dense vector: y[i] = x[perm[i]].

◆ row_permute()

template<typename Value, typename Parameters>
mat::compressed2D< Value, Parameters > mtl::sparse::util::row_permute ( const mat::compressed2D< Value, Parameters > & A,
const std::vector< std::size_t > & perm )

Apply a row permutation to a sparse matrix: B = P * A so B(pinv[old_row], :) = A(old_row, :).

◆ symmetric_permute()

template<typename Value, typename Parameters>
mat::compressed2D< Value, Parameters > mtl::sparse::util::symmetric_permute ( const mat::compressed2D< Value, Parameters > & A,
const std::vector< std::size_t > & perm )

Apply a symmetric permutation to a sparse matrix: B = P * A * P^T where P is the permutation matrix corresponding to perm.

perm[new] = old, so B(i,j) = A(perm[i], perm[j]).

◆ transpose_csc()

template<typename Value, typename SizeType>
csc_matrix< Value, SizeType > mtl::sparse::util::transpose_csc ( const csc_matrix< Value, SizeType > & A)

Compute the transpose of a CSC matrix (returns CSC).

Transpose of CSC is equivalent to interpreting CSR data as CSC.