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

Detailed description

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

Compressed sparse row (CSR) 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 csr_matrix is a sparse matrix container that stores an offset to the first entry of each row in matrix and one column entry per nonzero. The matrix may reside in either "host" or "device" memory depending on the MemorySpace. All entries in the csr_matrix are sorted according to row and internally sorted within each row by column index.
Note
The matrix entries within the same row must be sorted by column index.
The matrix should not contain duplicate entries.
Example
The following code snippet demonstrates how to create a 4-by-3 csr_matrix on the host with 6 nonzeros and then copies the matrix to the device.
// include the csr_matrix header file
#include <cusp/print.h>
int main()
{
// allocate storage for (4,3) matrix with 4 nonzeros
// initialize matrix entries on host
A.row_offsets[0] = 0; // first offset is always zero
A.row_offsets[1] = 2;
A.row_offsets[2] = 2;
A.row_offsets[3] = 3;
A.row_offsets[4] = 6; // last offset is always num_entries
A.column_indices[0] = 0; A.values[0] = 10;
A.column_indices[1] = 2; A.values[1] = 20;
A.column_indices[2] = 2; A.values[2] = 30;
A.column_indices[3] = 0; A.values[3] = 40;
A.column_indices[4] = 1; A.values[4] = 50;
A.column_indices[5] = 2; A.values[5] = 60;
// A now represents the following matrix
// [10 0 20]
// [ 0 0 0]
// [ 0 0 30]
// [40 50 60]
// copy to the device
}
Examples:
csr.cu, diagonal.cu, monitor.cu, and verbose_monitor.cu.

Definition at line 105 of file csr_matrix.h.

#include <csr_matrix.h>

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

Public Methods

 csr_matrix (void)
 
 csr_matrix (size_t num_rows, size_t num_cols, size_t num_entries)
 
template<typename MatrixType >
 csr_matrix (const MatrixType &matrix)
 
void resize (const size_t num_rows, const size_t num_cols, const size_t num_entries)
 
void swap (csr_matrix &matrix)
 
template<typename MatrixType >
csr_matrixoperator= (const MatrixType &matrix)
 

Public Members

row_offsets_array_type row_offsets
 
column_indices_array_type column_indices
 
values_array_type values
 

Constructor & Destructor Documentation

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

Construct an empty csr_matrix.

Definition at line 154 of file csr_matrix.h.

template<typename IndexType, typename ValueType, class MemorySpace>
cusp::csr_matrix< IndexType, ValueType, MemorySpace >::csr_matrix ( size_t  num_rows,
size_t  num_cols,
size_t  num_entries 
)
inline

Construct a csr_matrix with a specific shape and number of nonzero entries.

Parameters
num_rowsNumber of rows.
num_colsNumber of columns.
num_entriesNumber of nonzero matrix entries.

Definition at line 162 of file csr_matrix.h.

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

Construct a csr_matrix from another matrix.

Template Parameters
MatrixTypeType of input matrix used to create this csr_matrix.
Parameters
matrixAnother sparse or dense matrix.

Member Function Documentation

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

Assignment from another matrix.

Template Parameters
MatrixTypeType of input matrix to copy into this csr_matrix.
Parameters
matrixAnother sparse or dense matrix.
template<typename IndexType, typename ValueType, class MemorySpace>
void cusp::csr_matrix< IndexType, ValueType, MemorySpace >::resize ( const size_t  num_rows,
const size_t  num_cols,
const size_t  num_entries 
)

Resize matrix dimensions and underlying storage

Parameters
num_rowsNumber of rows.
num_colsNumber of columns.
num_entriesNumber of nonzero matrix entries.
template<typename IndexType, typename ValueType, class MemorySpace>
void cusp::csr_matrix< IndexType, ValueType, MemorySpace >::swap ( csr_matrix< IndexType, ValueType, MemorySpace > &  matrix)

Swap the contents of two csr_matrix objects.

Parameters
matrixAnother csr_matrix with the same IndexType and ValueType.

Member Data Documentation

template<typename IndexType, typename ValueType, class MemorySpace>
column_indices_array_type cusp::csr_matrix< IndexType, ValueType, MemorySpace >::column_indices

Storage for the column indices of the CSR data structure.

Definition at line 146 of file csr_matrix.h.

template<typename IndexType, typename ValueType, class MemorySpace>
row_offsets_array_type cusp::csr_matrix< IndexType, ValueType, MemorySpace >::row_offsets

Storage for the row offsets of the CSR data structure. Also called the "row pointer" array.

Definition at line 142 of file csr_matrix.h.

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

Storage for the nonzero entries of the CSR data structure.

Definition at line 150 of file csr_matrix.h.