MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
Loading...
Searching...
No Matches
mtl::permutation_matrix< Value > Class Template Reference

Implicit permutation matrix – stores only perm vector, O(n) storage. More...

#include <permutation_matrix.hpp>

Public Types

using value_type = Value
using size_type = std::size_t
using const_reference = Value
using reference = Value

Public Member Functions

 permutation_matrix (std::vector< size_type > perm)
 Construct from permutation vector: perm[i] = column of the 1 in row i.
 permutation_matrix (std::initializer_list< size_type > perm)
 Construct from a braced list of entries: P({2, 0, 1}), and P({0}) is the 1x1 permutation.
 permutation_matrix (size_type n)
 Construct identity permutation of size n.
value_type operator() (size_type r, size_type c) const
size_type num_rows () const
size_type num_cols () const
size_type size () const
const std::vector< size_type > & permutation () const
 Direct access to the permutation vector.
void swap_rows (size_type i, size_type j)
 Swap rows i and j (elementary row transposition).
permutation_matrix inverse () const
 Return the inverse permutation matrix (transpose).

Detailed Description

template<typename Value = double>
class mtl::permutation_matrix< Value >

Implicit permutation matrix – stores only perm vector, O(n) storage.

Row i maps to column perm[i]: P(i, j) = (perm[i] == j) ? 1 : 0

Member Typedef Documentation

◆ const_reference

template<typename Value = double>
using mtl::mat::permutation_matrix< Value >::const_reference = Value

◆ reference

template<typename Value = double>
using mtl::mat::permutation_matrix< Value >::reference = Value

◆ size_type

template<typename Value = double>
using mtl::mat::permutation_matrix< Value >::size_type = std::size_t

◆ value_type

template<typename Value = double>
using mtl::mat::permutation_matrix< Value >::value_type = Value

Constructor & Destructor Documentation

◆ permutation_matrix() [1/3]

template<typename Value = double>
mtl::mat::permutation_matrix< Value >::permutation_matrix ( std::vector< size_type > perm)
inlineexplicit

Construct from permutation vector: perm[i] = column of the 1 in row i.

It must be a permutation of 0..n-1, checked once, in every build (#826): a duplicate or out-of-range entry made inverse() and P * x index out of bounds. Throws std::invalid_argument (throw_or_abort).

◆ permutation_matrix() [2/3]

template<typename Value = double>
mtl::mat::permutation_matrix< Value >::permutation_matrix ( std::initializer_list< size_type > perm)
inline

Construct from a braced list of entries: P({2, 0, 1}), and P({0}) is the 1x1 permutation.

Without it, {0} picked the size constructor and gave a 0x0 matrix, and {2} the 2x2 identity (#826). For the identity of size n, use P(n) with parentheses.

◆ permutation_matrix() [3/3]

template<typename Value = double>
mtl::mat::permutation_matrix< Value >::permutation_matrix ( size_type n)
inlineexplicit

Construct identity permutation of size n.

Member Function Documentation

◆ inverse()

template<typename Value = double>
permutation_matrix mtl::mat::permutation_matrix< Value >::inverse ( ) const
inline

Return the inverse permutation matrix (transpose).

◆ num_cols()

template<typename Value = double>
size_type mtl::mat::permutation_matrix< Value >::num_cols ( ) const
inline

◆ num_rows()

template<typename Value = double>
size_type mtl::mat::permutation_matrix< Value >::num_rows ( ) const
inline

◆ operator()()

template<typename Value = double>
value_type mtl::mat::permutation_matrix< Value >::operator() ( size_type r,
size_type c ) const
inline

◆ permutation()

template<typename Value = double>
const std::vector< size_type > & mtl::mat::permutation_matrix< Value >::permutation ( ) const
inline

Direct access to the permutation vector.

◆ size()

template<typename Value = double>
size_type mtl::mat::permutation_matrix< Value >::size ( ) const
inline

◆ swap_rows()

template<typename Value = double>
void mtl::mat::permutation_matrix< Value >::swap_rows ( size_type i,
size_type j )
inline

Swap rows i and j (elementary row transposition).


The documentation for this class was generated from the following file: