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

Detailed description

template<typename IndexType, typename ValueType, class MemorySpace>
class cusp::dia_matrix< IndexType, ValueType, MemorySpace >

Diagonal (DIA) representation a sparse matrix.

Template Parameters
IndexTypeType used for matrix indices (e.g. int).
ValueTypeType used for matrix values (e.g. float).
MemorySpaceA memory space (e.g. cusp::host_memory or cusp::device_memory)
Overview
A dia_matrix is a sparse matrix container that stores each nonzero in a dense array2d container according to the diagonal each nonzero resides, the diagonal index of an ( i , j ) entry is | i - j |. This storage format is applicable to small set of matrices with significant structure. Storing the underlying entries in a array2d container avoids additional overhead associated with row or column indices but requires the storage of invalid entries associated with incomplete diagonals.
Note
The diagonal offsets should not contain duplicate entries.
Example
The following code snippet demonstrates how to create a 4-by-3 dia_matrix on the host with 3 diagonals (6 total nonzeros) and then copies the matrix to the device.
// include dia_matrix header file
#include <cusp/print.h>
int main()
{
// allocate storage for (4,3) matrix with 6 nonzeros in 3 diagonals
// initialize diagonal offsets
A.diagonal_offsets[0] = -2;
A.diagonal_offsets[1] = 0;
A.diagonal_offsets[2] = 1;
// initialize diagonal values
// first diagonal
A.values(0,2) = 0; // outside matrix
A.values(1,2) = 0; // outside matrix
A.values(2,0) = 40;
A.values(3,0) = 60;
// second diagonal
A.values(0,1) = 10;
A.values(1,1) = 0;
A.values(2,1) = 50;
A.values(3,1) = 50; // outside matrix
// third diagonal
A.values(0,2) = 20;
A.values(1,2) = 30;
A.values(2,2) = 0; // outside matrix
A.values(3,2) = 0; // outside matrix
// A now represents the following matrix
// [10 20 0]
// [ 0 0 30]
// [40 0 50]
// [ 0 60 0]
// copy to the device
// print the constructed dia_matrix
}
Examples:
dia.cu.

Definition at line 119 of file dia_matrix.h.

#include <dia_matrix.h>

Inheritance diagram for cusp::dia_matrix< IndexType, ValueType, MemorySpace >:

Public Methods

 dia_matrix (void)
 
 dia_matrix (const size_t num_rows, const size_t num_cols, const size_t num_entries, const size_t num_diagonals, const size_t alignment=32)
 
template<typename MatrixType >
 dia_matrix (const MatrixType &matrix)
 
void resize (const size_t num_rows, const size_t num_cols, const size_t num_entries, const size_t num_diagonals)
 
void resize (const size_t num_rows, const size_t num_cols, const size_t num_entries, const size_t num_diagonals, const size_t alignment)
 
void swap (dia_matrix &matrix)
 
template<typename MatrixType >
dia_matrixoperator= (const MatrixType &matrix)
 

Public Members

diagonal_offsets_array_type diagonal_offsets
 
values_array_type values
 

Constructor & Destructor Documentation

template<typename IndexType, typename ValueType, class MemorySpace>
cusp::dia_matrix< IndexType, ValueType, MemorySpace >::dia_matrix ( void  )
inline

Construct an empty dia_matrix_view.

Definition at line 165 of file dia_matrix.h.

template<typename IndexType, typename ValueType, class MemorySpace>
cusp::dia_matrix< IndexType, ValueType, MemorySpace >::dia_matrix ( const size_t  num_rows,
const size_t  num_cols,
const size_t  num_entries,
const size_t  num_diagonals,
const size_t  alignment = 32 
)

Construct a dia_matrix with a specific shape, number of nonzero entries, and number of occupied diagonals.

Parameters
num_rowsNumber of rows.
num_colsNumber of columns.
num_entriesNumber of nonzero matrix entries.
num_diagonalsNumber of occupied diagonals.
alignmentAmount of padding used to align the data structure (default 32).
template<typename IndexType, typename ValueType, class MemorySpace>
template<typename MatrixType >
cusp::dia_matrix< IndexType, ValueType, MemorySpace >::dia_matrix ( const MatrixType &  matrix)

Construct a dia_matrix from another matrix.

Parameters
matrixAnother sparse or dense matrix.

Member Function Documentation

template<typename IndexType, typename ValueType, class MemorySpace>
template<typename MatrixType >
dia_matrix& cusp::dia_matrix< IndexType, ValueType, MemorySpace >::operator= ( const MatrixType &  matrix)

Assignment from another matrix.

Parameters
matrixAnother sparse or dense matrix.
template<typename IndexType, typename ValueType, class MemorySpace>
void cusp::dia_matrix< IndexType, ValueType, MemorySpace >::resize ( const size_t  num_rows,
const size_t  num_cols,
const size_t  num_entries,
const size_t  num_diagonals 
)

Resize matrix dimensions and underlying storage

Parameters
num_rowsNumber of rows.
num_colsNumber of columns.
num_entriesNumber of nonzero matrix entries.
num_diagonalsNumber of occupied diagonals.
template<typename IndexType, typename ValueType, class MemorySpace>
void cusp::dia_matrix< IndexType, ValueType, MemorySpace >::resize ( const size_t  num_rows,
const size_t  num_cols,
const size_t  num_entries,
const size_t  num_diagonals,
const size_t  alignment 
)

Resize matrix dimensions and underlying storage

Parameters
num_rowsNumber of rows.
num_colsNumber of columns.
num_entriesNumber of nonzero matrix entries.
num_diagonalsNumber of occupied diagonals.
alignmentAmount of padding used to align the data structure (default 32).
template<typename IndexType, typename ValueType, class MemorySpace>
void cusp::dia_matrix< IndexType, ValueType, MemorySpace >::swap ( dia_matrix< IndexType, ValueType, MemorySpace > &  matrix)

Swap the contents of two dia_matrix objects.

Parameters
matrixAnother dia_matrix with the same IndexType and ValueType.

Member Data Documentation

template<typename IndexType, typename ValueType, class MemorySpace>
diagonal_offsets_array_type cusp::dia_matrix< IndexType, ValueType, MemorySpace >::diagonal_offsets

Storage for the diagonal offsets.

Definition at line 156 of file dia_matrix.h.

template<typename IndexType, typename ValueType, class MemorySpace>
values_array_type cusp::dia_matrix< IndexType, ValueType, MemorySpace >::values

Storage for the nonzero entries of the DIA data structure.

Definition at line 160 of file dia_matrix.h.