CUSP
Loading...
Searching...
No Matches
cusp::permutation_matrix< IndexType, MemorySpace > Class Template Reference

#include <permutation_matrix.h>

Inheritance diagram for cusp::permutation_matrix< IndexType, MemorySpace >:

Public Methods

 permutation_matrix (void)
 
 permutation_matrix (const size_t num_rows)
 
template<typename MemorySpace2 >
 permutation_matrix (const permutation_matrix< IndexType, MemorySpace2 > &matrix)
 
template<typename ArrayType >
 permutation_matrix (const size_t num_rows, const ArrayType &permutation)
 
void resize (const size_t num_rows)
 
void swap (permutation_matrix &matrix)
 
template<typename MatrixType >
void symmetric_permute (MatrixType &matrix)
 

Public Members

permutation_array_type permutation
 

Detailed description

template<typename IndexType, typename MemorySpace>
class cusp::permutation_matrix< IndexType, MemorySpace >

Simple representation a permutation matrix.

Template Parameters
IndexTypeType used for matrix indices (e.g. int).
MemorySpaceA memory space (e.g. cusp::host_memory or cusp::device_memory)
Overview
This matrix represents a row permutation of the identity matrix.
Example
The following code snippet demonstrates how to create a 3-by-3 permutation_matrix on the host with 3 nonzeros and permutes a coo_matrix by first by row and then by column.
// include the permutation_matrix header file
#include <cusp/multiply.h>
#include <cusp/print.h>
int main()
{
typedef cusp::host_memory MemorySpace;
// allocate storage for (3,3) matrix with 5 nonzeros
// initialize matrix entries on host
A.row_indices[0] = 0; A.column_indices[0] = 0; A.values[0] = 10;
A.row_indices[1] = 0; A.column_indices[1] = 1; A.values[1] = 20;
A.row_indices[2] = 0; A.column_indices[2] = 2; A.values[2] = 30;
A.row_indices[3] = 1; A.column_indices[3] = 0; A.values[3] = 40;
A.row_indices[4] = 1; A.column_indices[4] = 1; A.values[4] = 50;
A.row_indices[5] = 2; A.column_indices[5] = 0; A.values[5] = 60;
A.row_indices[6] = 2; A.column_indices[6] = 2; A.values[6] = 70;
// A now represents the following matrix
// [10 0 20]
// [30 40 0]
// [ 0 0 50]
// generate a index permutation that swaps row or column 0 and 2
permutation[0] = 2; // 0 maps to 2
permutation[1] = 1; // 1 maps to 1
permutation[2] = 0; // 2 maps to 0
// allocate storage for (3,3) matrix with 3 nonzeros
// P now represents the following permutation matrix
// [0 0 1]
// [0 1 0]
// [1 0 0]
// permute the rows of A
cusp::multiply(P, A, PA);
// permute the column of PA
cusp::multiply(PA, P, PAP);
// print the matrix
// print the permuted matrix
}
The array1d class is a 1D vector container that may contain elements stored in "host" or "device" mem...
Definition array1d.h:99
The array2d class is a 2D vector container that may contain elements stored in "host" or "device" mem...
Definition array2d.h:94
Coordinate (COO) representation a sparse matrix.
Definition coo_matrix.h:117
Simple representation a permutation matrix.
permutation_array_type permutation
Coordinate matrix format.
void print(const Printable &p)
print a textual representation of an object
void multiply(const LinearOperator &A, const MatrixOrVector1 &B, MatrixOrVector2 &C)
Implements matrix-matrix and matrix-vector multiplication.
Matrix multiplication.
A permutation matrix.
Print textual representation of an object.

Definition at line 108 of file permutation_matrix.h.

Constructor & Destructor Documentation

◆ permutation_matrix() [1/4]

template<typename IndexType , typename MemorySpace >
cusp::permutation_matrix< IndexType, MemorySpace >::permutation_matrix ( void  )
inline

Construct an empty permutation_matrix.

Definition at line 143 of file permutation_matrix.h.

◆ permutation_matrix() [2/4]

template<typename IndexType , typename MemorySpace >
cusp::permutation_matrix< IndexType, MemorySpace >::permutation_matrix ( const size_t  num_rows)
inline

Construct a permutation_matrix with a specific number of rows.

Parameters
num_rowsNumber of rows.

Definition at line 149 of file permutation_matrix.h.

◆ permutation_matrix() [3/4]

template<typename IndexType , typename MemorySpace >
template<typename MemorySpace2 >
cusp::permutation_matrix< IndexType, MemorySpace >::permutation_matrix ( const permutation_matrix< IndexType, MemorySpace2 > &  matrix)
inline

Construct a permutation_matrix from another matrix.

Template Parameters
MemorySpace2Memory space of the input matrix
Parameters
matrixAnother sparse or dense matrix.

Definition at line 160 of file permutation_matrix.h.

◆ permutation_matrix() [4/4]

template<typename IndexType , typename MemorySpace >
template<typename ArrayType >
cusp::permutation_matrix< IndexType, MemorySpace >::permutation_matrix ( const size_t  num_rows,
const ArrayType &  permutation 
)
inline

Construct a permutation_matrix from another matrix.

Template Parameters
ArrayTypepermutation array type
Parameters
num_rowsNumber of rows.
permutationArray containing the permutation indices.

Definition at line 171 of file permutation_matrix.h.

Member Function Documentation

◆ resize()

template<typename IndexType , typename MemorySpace >
void cusp::permutation_matrix< IndexType, MemorySpace >::resize ( const size_t  num_rows)

Resize matrix dimensions and underlying storage

Parameters
num_rowsNumber of rows.

◆ swap()

template<typename IndexType , typename MemorySpace >
void cusp::permutation_matrix< IndexType, MemorySpace >::swap ( permutation_matrix< IndexType, MemorySpace > &  matrix)

Swap the contents of two permutation_matrix objects.

Parameters
matrixAnother permutation_matrix with the same IndexType.

◆ symmetric_permute()

template<typename IndexType , typename MemorySpace >
template<typename MatrixType >
void cusp::permutation_matrix< IndexType, MemorySpace >::symmetric_permute ( MatrixType &  matrix)

Permute rows and columns of matrix elements

Template Parameters
MatrixTypeType of input matrix to permute
Parameters
matrixInput matrix to apply symmetric permutation.

Member Data Documentation

◆ permutation

template<typename IndexType , typename MemorySpace >
permutation_array_type cusp::permutation_matrix< IndexType, MemorySpace >::permutation

Storage for the permutation indices

Definition at line 139 of file permutation_matrix.h.