geomc 1.0
A c++ linear algebra template library
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Friends | List of all members
PermutationMatrix< N > Class Template Reference

A matrix which, by multiplication, permutes the rows or columns of another matrix. More...

#include <geomc/linalg/mtxtypes/PermutationMatrix.h>

Inheritance diagram for PermutationMatrix< N >:
MatrixBase< bool, N, N, PermutationMatrix< N > > PermuteMatrixBase< N >

Public Types

typedef bool elem_t
 Element type.
 
typedef MtxSubsetIterator< const PermutationMatrix< N >, const elem_tconst_iterator
 Read-only row-major iterator over matrix elements.
 
typedef const_iterator const_region_iterator
 Read-only row-major iterator over the matrix elements in a rectangular region.
 
typedef MtxRowIterator< const PermutationMatrix< N >, const elem_tconst_row_iterator
 Read-only iterator over the elments of a row.
 
typedef MtxColIterator< const PermutationMatrix< N >, const elem_tconst_col_iterator
 Read-only iterator over the elements of a column.
 
typedef Storage< storage_token_t, _ImplStorageObjCount< PermutationMatrix< N > >::count > storagebuffer_t
 
typedef PermutationMatrix< N > recurring_t
 

Public Member Functions

 PermutationMatrix ()
 
 PermutationMatrix (index_t n)
 
index_t sign ()
 
index_t rows () const
 
index_t cols () const
 
const index_t * getRowSources () const
 
const index_t * getColSources () const
 
const index_t * getColDestinations () const
 
const index_t * getRowDestinations () const
 
void setRowSources (const index_t *p)
 
void setColSources (const index_t *p)
 
void setRowDestinations (const index_t *p)
 
void setColDestinations (const index_t *p)
 
void swap_rows (index_t a, index_t b)
 
void swap_cols (index_t a, index_t b)
 
bool operator() (index_t row, index_t col) const
 
void set_identity ()
 
void transpose ()
 
void get_storage_tokens (storage_token_t *buf) const
 
constexpr index_t storage_token_count () const
 
derived_const_row_iterator operator[] (index_t i) const
 
const_row_iterator row (index_t i) const
 
const_col_iterator col (index_t i) const
 
const_iterator begin () const
 
const_iterator end () const
 
const_region_iterator region_begin (const MatrixRegion &r) const
 
const_region_iterator region_end (const MatrixRegion &r) const
 
storagebuffer_t get_storage_token_buffer () const
 

Static Public Attributes

static constexpr index_t ROWDIM
 Row dimension template parameter.
 
static constexpr index_t COLDIM
 Column dimension template parameter.
 

Protected Member Functions

index_t _rows () const
 
index_t _cols () const
 
index_t * getSrcData ()
 
const index_t * getSrcData () const
 
index_t * getDstData ()
 
const index_t * getDstData () const
 
void swapPointers ()
 

Friends

template<typename Md , typename Ma , typename Mb >
class detail::_ImplMtxMul
 
bool detail::mtxequal (const PermutationMatrix< N > &a, const PermutationMatrix< N > &b)
 

Detailed Description

template<index_t N>
class geom::PermutationMatrix< N >

A matrix which, by multiplication, permutes the rows or columns of another matrix.

A permutation matrix P permutes rows if left-multiplied (P * M), and permutes columns if right-multiplied (M * P).

Permutation matrices are always (n x n) and have only elements that are zero or 1. Each row and column has exactly one 1 element.

An (n x n) permutation matrix uses O(n) storage, and multiplications by other matrices are optimized to perform the permutation directly in _O(n2)_ (rather than _O(n3)_) time. Multiplication of two permutation matrices is O(n).

Constructor & Destructor Documentation

◆ PermutationMatrix() [1/2]

PermutationMatrix ( )
inline

Construct a new identity permutation matrix.

◆ PermutationMatrix() [2/2]

PermutationMatrix ( index_t  n)
inlineexplicit

Construct a new identity permutation matrix of size n. (Dynamic only).

Member Function Documentation

◆ begin()

const_iterator begin ( ) const
inlineinherited
Returns
A read-only random-access row major-ordered iterator over the elements of this matrix, pointing to the element at (0,0).

◆ col()

const_col_iterator col ( index_t  i) const
inlineinherited
Parameters
iIndex of column (zero-indexed)
Returns
A const iterator over the elements of column i

◆ cols()

index_t cols ( ) const
inline
Returns
Number of columns in the matrix. Always equal to the number of rows.

◆ end()

const_iterator end ( ) const
inlineinherited
Returns
A read-only random-access row major-ordered iterator over the elements of this matrix, pointing to the element just beyond the last element in the lower right corner.

◆ getColDestinations()

const index_t * getColDestinations ( ) const
inline

Array containing a mapping of source columns to destination columns in a column-permuting operation.

In other words, given the column-permuting multiplication:

M * P = D

return an array a such that column Da[i]= Mi.

Because of the property that a permutation matrix's inverse is its transpose, this function is equivalent to getRowSources().

◆ getColSources()

const index_t * getColSources ( ) const
inline

Array containing a mapping of destination columns to source columns in a column-permuting operation.

In other words, given the column-permuting multiplicaton:

M * P = D

return an array a such that column Di= Ma[i].

◆ getRowDestinations()

const index_t * getRowDestinations ( ) const
inline

Array containing a mapping of source rows to destination rows in a row-permuting operation.

In other words, given the row-permuting multiplication:

P * M = D

return an array a such that row Da[i]= Mi.

Because of the property that a permutation matrix's inverse is its transpose, this function is equivalent to getColSources().

◆ getRowSources()

const index_t * getRowSources ( ) const
inline

Array containing a mapping of destination rows to source rows in a row-permuting operation.

In other words, given the row-permuting multiplicaton:

P * M = D

return an array a such that row Di= Ma[i].

◆ operator()()

bool operator() ( index_t  row,
index_t  col 
) const
inline

Get the element at (row, col).

Parameters
rowZero-indexed row coordinate
colZero-indexed column coordinate
Returns
The element at (row, col); either 0 or 1.

◆ operator[]()

derived_const_row_iterator operator[] ( index_t  i) const
inlineinherited
Parameters
iIndex of row (zero-indexed)
Returns
A const iterator over the elements of row i

◆ region_begin()

const_region_iterator region_begin ( const MatrixRegion r) const
inlineinherited
Parameters
rThe zero-indexed region to iterate over. The upper extreme coordinates represent the index just beyond the last element to be iterated over.
Returns
A read-only, random-access, row-major iterator over the elements in region r, pointing at the first element in the region (upper left corner).

◆ region_end()

const_region_iterator region_end ( const MatrixRegion r) const
inlineinherited
Parameters
rThe zero-indexed region to iterate over. The upper extreme coordinates represent the index just beyond the last element to be iterated over.
Returns
A read-only, random-access, row-major iterator over the elements in region r, pointing at the element just beyond the last element in the region.

◆ row()

const_row_iterator row ( index_t  i) const
inlineinherited
Parameters
iIndex of row (zero-indexed)
Returns
A const iterator over the elements of row i

◆ rows()

index_t rows ( ) const
inline
Returns
Number of rows in the matrix. Always equal to the number of columns.

◆ set_identity()

void set_identity ( )
inline

Reset this matrix to the identity permutation.

◆ setColDestinations()

void setColDestinations ( const index_t *  p)
inline

Set the permutation described by this matrix by passing an array mapping source columns to destination columns in a column-permuting operation.

In other words, define the column-permuting multiplication:

M * P = D

with an array a such that column Da[i]= Mi.

Because of the property that a permutation matrix's inverse is its transpose, this function is equivalent to setRowSources().

Parameters
pArray of indecies.

◆ setColSources()

void setColSources ( const index_t *  p)
inline

Set the permutation described by this matrix by passing a mapping of destination columns to source columns in a column-permuting operation.

In other words, define the column-permuting multiplicaton:

M * P = D

with an array a such that column Di= Ma[i].

Parameters
pArray of indecies.

◆ setRowDestinations()

void setRowDestinations ( const index_t *  p)
inline

Set the permutation described by this matrix by passing an array mapping source rows to destination rows in a row-permuting operation.

In other words, define the row-permuting multiplication:

P * M = D

with an array a such that row Da[i]= Mi.

Because of the property that a permutation matrix's inverse is its transpose, this function is equivalent to setColSources().

Parameters
pArray of indecies.

◆ setRowSources()

void setRowSources ( const index_t *  p)
inline

Set the permutation described by this matrix by passing a mapping of destination rows to source rows in a row-permuting operation.

In other words, define the row-permuting multiplicaton:

P * M = D

with an array a such that row Di= Ma[i].

Parameters
pArray of indecies.

◆ sign()

index_t sign ( )
inline

Compute the signature of this permutation.

Runs in O(n) time; or O(1) time if previously computed.

Returns
-1 if the number of transpositions in this permutation is odd, 1 otherwise.

◆ swap_cols()

void swap_cols ( index_t  a,
index_t  b 
)
inline

Adjust this matrix such that columns a and b are swapped in the destination matrix after applying a column permutation. This operation is cumulative on any previous swaps.

Parameters
aA column index.
bA column index.

◆ swap_rows()

void swap_rows ( index_t  a,
index_t  b 
)
inline

Adjust this matrix such that rows a and b are swapped in the destination matrix after applying a row permutation. This operation is cumulative on any previous swaps.

Parameters
aA row index.
bA row index.

◆ transpose()

void transpose ( )
inline

Transpose this matrix in-place in O(1) time. For this type of matrix, also the inverse matrix.


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