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

Detailed description

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

Coordinate (COO) 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 coo_matrix is a sparse matrix container that stores one row and column entry per nonzero. The matrix may reside in either "host" or "device" memory depending on the MemorySpace. All entries in the coo_matrix are sorted according to row indices and internally within each row sorted by column indices.
Note
The matrix entries must be sorted by row index.
The matrix should not contain duplicate entries.
Example
The following code snippet demonstrates how to create a 4-by-3 coo_matrix on the host with 6 nonzeros and then copies the matrix to the device.
// include coo_matrix header file
#include <cusp/print.h>
int main()
{
// allocate storage for (4,3) matrix with 6 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] = 2; A.values[1] = 20;
A.row_indices[2] = 2; A.column_indices[2] = 2; A.values[2] = 30;
A.row_indices[3] = 3; A.column_indices[3] = 0; A.values[3] = 40;
A.row_indices[4] = 3; A.column_indices[4] = 1; A.values[4] = 50;
A.row_indices[5] = 3; 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
// print the constructed coo_matrix
return 0;
}
Examples:
ainv.cu, coo.cu, custom_amg.cu, diffusion.cu, matrix_market.cu, maximal_independent_set.cu, poisson.cu, smoothed_aggregation.cu, and unordered_triplets.cu.

Definition at line 106 of file coo_matrix.h.

#include <coo_matrix.h>

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

Public Methods

 coo_matrix (void)
 
 coo_matrix (const size_t num_rows, const size_t num_cols, const size_t num_entries)
 
template<typename MatrixType >
 coo_matrix (const MatrixType &matrix)
 
void resize (size_t num_rows, size_t num_cols, size_t num_entries)
 
void swap (coo_matrix &matrix)
 
template<typename MatrixType >
coo_matrixoperator= (const MatrixType &matrix)
 
void sort_by_row (void)
 
void sort_by_row_and_column (void)
 
bool is_sorted_by_row (void)
 
bool is_sorted_by_row_and_column (void)
 

Public Members

row_indices_array_type row_indices
 
column_indices_array_type column_indices
 
values_array_type values
 

Constructor & Destructor Documentation

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

Construct an empty coo_matrix.

Definition at line 157 of file coo_matrix.h.

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

Construct a coo_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 165 of file coo_matrix.h.

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

Construct a coo_matrix from another matrix.

Parameters
matrixAnother sparse or dense matrix.

Member Function Documentation

template<typename IndexType, typename ValueType, class MemorySpace>
bool cusp::coo_matrix< IndexType, ValueType, MemorySpace >::is_sorted_by_row ( void  )

Determine whether matrix elements are sorted by row index

Returns
false, if the row indices are unsorted; true, otherwise.
template<typename IndexType, typename ValueType, class MemorySpace>
bool cusp::coo_matrix< IndexType, ValueType, MemorySpace >::is_sorted_by_row_and_column ( void  )

Determine whether matrix elements are sorted by row and column index

Returns
false, if the row and column indices are unsorted; true, otherwise.
template<typename IndexType, typename ValueType, class MemorySpace>
template<typename MatrixType >
coo_matrix& cusp::coo_matrix< IndexType, ValueType, MemorySpace >::operator= ( const MatrixType &  matrix)

Assignment from another matrix.

Parameters
matrixAnother sparse or dense matrix.
Returns
coo_matrix constructed from existing matrix.
template<typename IndexType, typename ValueType, class MemorySpace>
void cusp::coo_matrix< IndexType, ValueType, MemorySpace >::resize ( size_t  num_rows,
size_t  num_cols,
size_t  num_entries 
)

Resize matrix dimensions and underlying storage

template<typename IndexType, typename ValueType, class MemorySpace>
void cusp::coo_matrix< IndexType, ValueType, MemorySpace >::sort_by_row ( void  )

Sort matrix elements by row index

template<typename IndexType, typename ValueType, class MemorySpace>
void cusp::coo_matrix< IndexType, ValueType, MemorySpace >::sort_by_row_and_column ( void  )

Sort matrix elements by row and column index

template<typename IndexType, typename ValueType, class MemorySpace>
void cusp::coo_matrix< IndexType, ValueType, MemorySpace >::swap ( coo_matrix< IndexType, ValueType, MemorySpace > &  matrix)

Swap the contents of two coo_matrix objects.

Parameters
matrixAnother coo_matrix with the same IndexType and ValueType.

Member Data Documentation

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

Storage for the column indices of the COO data structure.

Definition at line 149 of file coo_matrix.h.

template<typename IndexType, typename ValueType, class MemorySpace>
row_indices_array_type cusp::coo_matrix< IndexType, ValueType, MemorySpace >::row_indices

Storage for the row indices of the COO data structure.

Definition at line 145 of file coo_matrix.h.

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

Storage for the nonzero entries of the COO data structure.

Definition at line 153 of file coo_matrix.h.