Fork me on GitHub
 All Classes Files Functions Variables Groups Pages
Public Methods | Public Members | List of all members
cusp::permutation_matrix< IndexType, MemorySpace > Class Template Reference

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
}

Definition at line 108 of file permutation_matrix.h.

#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
 

Constructor & Destructor Documentation

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.

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.

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.

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

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.
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.
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

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.