MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
Loading...
Searching...
No Matches
permutation.hpp File Reference
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <numeric>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
#include <mtl/mat/compressed2D.hpp>
#include <mtl/mat/inserter.hpp>

Namespaces

namespace  mtl
namespace  mtl::sparse
namespace  mtl::sparse::util
namespace  mtl::sparse::util::detail

Functions

std::vector< std::size_t > mtl::sparse::util::invert_permutation (const std::vector< std::size_t > &p)
 Compute the inverse of a permutation vector.
std::vector< std::size_t > mtl::sparse::util::identity_permutation (std::size_t n)
 Return the identity permutation of size n: p[i] = i.
std::vector< std::size_t > mtl::sparse::util::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 mtl::sparse::util::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, typename Fill>
mat::compressed2D< Value, Parameters > mtl::sparse::util::detail::csr_from_rows (std::size_t nrows, std::size_t ncols, std::size_t nnz, Fill &&fill)
 A compressed2D built row by row, without an inserter (issue 908): the default inserter's 5 slots per row sent longer rows to its std::map, and a permutation keeps every row whole, so the rows can be written directly.
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.
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]).
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, :).
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]].
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].