Algorithms for processing matrices in sparse and dense formats. More...
Functions | |
template<typename SourceType , typename DestinationType > | |
void | cusp::convert (const SourceType &src, DestinationType &dst) |
Convert between matrix formats. More... | |
template<typename SourceType , typename DestinationType > | |
void | cusp::copy (const SourceType &src, DestinationType &dst) |
Copy one array or matrix to another. More... | |
template<typename MatrixType1 , typename MatrixType2 , typename MatrixType3 , typename BinaryFunction > | |
void | cusp::elementwise (const MatrixType1 &A, const MatrixType2 &B, MatrixType3 &C, BinaryFunction op) |
Perform transform operation on two matrices. More... | |
template<typename MatrixType1 , typename MatrixType2 , typename MatrixType3 > | |
void | cusp::add (const MatrixType1 &A, const MatrixType2 &B, MatrixType3 &C) |
Compute the sum of two matrices. More... | |
template<typename MatrixType1 , typename MatrixType2 , typename MatrixType3 > | |
void | cusp::subtract (const MatrixType1 &A, const MatrixType2 &B, MatrixType3 &C) |
Compute the difference of two matrices. More... | |
template<typename OffsetArray , typename IndexArray > | |
void | cusp::offsets_to_indices (const OffsetArray &offsets, IndexArray &indices) |
Expand CSR row offsets to COO row indices. More... | |
template<typename IndexArray , typename OffsetArray > | |
void | cusp::indices_to_offsets (const IndexArray &indices, OffsetArray &offsets) |
Compress COO row indices to CSR row offsets. More... | |
template<typename MatrixType , typename ArrayType > | |
void | cusp::extract_diagonal (const MatrixType &A, ArrayType &output) |
Extract the main diagonal of a matrix. More... | |
template<typename ArrayType1 , typename ArrayType2 > | |
size_t | cusp::count_diagonals (const size_t num_rows, const size_t num_cols, const ArrayType1 &row_indices, const ArrayType2 &column_indices) |
Count the number of occupied diagonals in the input matrix. More... | |
template<typename ArrayType > | |
size_t | cusp::compute_max_entries_per_row (const ArrayType &row_offsets) |
Compute the maximum row length of a matrix. More... | |
template<typename ArrayType > | |
size_t | cusp::compute_optimal_entries_per_row (const ArrayType &row_offsets, float relative_speed=3.0f, size_t breakeven_threshold=4096) |
Compute the optimal number of entries per row of HYB matrix. More... | |
template<typename LinearOperator , typename MatrixOrVector1 , typename MatrixOrVector2 > | |
void | cusp::multiply (const LinearOperator &A, const MatrixOrVector1 &B, MatrixOrVector2 &C) |
Implements matrix-matrix and matrix-vector multiplication. More... | |
template<typename LinearOperator , typename MatrixOrVector1 , typename MatrixOrVector2 , typename UnaryFunction , typename BinaryFunction1 , typename BinaryFunction2 > | |
void | cusp::multiply (const LinearOperator &A, const MatrixOrVector1 &B, MatrixOrVector2 &C, UnaryFunction initialize, BinaryFunction1 combine, BinaryFunction2 reduce) |
Implements matrix-vector multiplication with custom combine and reduce functionality. More... | |
template<typename LinearOperator , typename MatrixOrVector1 , typename MatrixOrVector2 , typename UnaryFunction , typename BinaryFunction1 , typename BinaryFunction2 > | |
void | cusp::generalized_spgemm (const LinearOperator &A, const MatrixOrVector1 &B, MatrixOrVector2 &C, UnaryFunction initialize, BinaryFunction1 combine, BinaryFunction2 reduce) |
Implements generalized matrix-matrix multiplication. More... | |
template<typename LinearOperator , typename Vector1 , typename Vector2 , typename Vector3 , typename BinaryFunction1 , typename BinaryFunction2 > | |
void | cusp::generalized_spmv (const LinearOperator &A, const Vector1 &x, const Vector2 &y, Vector3 &z, BinaryFunction1 combine, BinaryFunction2 reduce) |
Implements generalized matrix-vector multiplication. More... | |
template<typename ArrayType > | |
void | cusp::counting_sort (ArrayType &keys, typename ArrayType::value_type min, typename ArrayType::value_type max) |
Use counting sort to order an array. More... | |
template<typename ArrayType1 , typename ArrayType2 > | |
void | cusp::counting_sort_by_key (ArrayType1 &keys, ArrayType2 &vals, typename ArrayType1::value_type min, typename ArrayType1::value_type max) |
Use counting sort to order an array and permute an array of values. More... | |
template<typename ArrayType1 , typename ArrayType2 , typename ArrayType3 > | |
void | cusp::sort_by_row (ArrayType1 &row_indices, ArrayType2 &column_indices, ArrayType3 &values, typename ArrayType1::value_type min_row=0, typename ArrayType1::value_type max_row=0) |
Sort matrix indices by row. More... | |
template<typename ArrayType1 , typename ArrayType2 , typename ArrayType3 > | |
void | cusp::sort_by_row_and_column (ArrayType1 &row_indices, ArrayType2 &column_indices, ArrayType3 &values, typename ArrayType1::value_type min_row=0, typename ArrayType1::value_type max_row=0, typename ArrayType2::value_type min_col=0, typename ArrayType2::value_type max_col=0) |
Sort matrix indices by row and column. More... | |
template<typename MatrixType1 , typename MatrixType2 > | |
void | cusp::transpose (const MatrixType1 &A, MatrixType2 &At) |
Transpose a matrix. More... | |
template<typename MatrixType > | |
bool | cusp::is_valid_matrix (const MatrixType &matrix) |
Validate format of a given matrix. More... | |
template<typename MatrixType , typename OutputStream > | |
bool | cusp::is_valid_matrix (const MatrixType &matrix, OutputStream &ostream) |
Validate format of a given matrix. More... | |
template<typename MatrixType > | |
void | cusp::assert_is_valid_matrix (const MatrixType &matrix) |
Validate format of a given matrix and exit if invalid. More... | |
template<typename Array1 , typename Array2 > | |
void | cusp::assert_same_dimensions (const Array1 &array1, const Array2 &array2) |
Assert dimensions of two arrays are equal. Throw invalid input exception if dimensions do not match. More... | |
template<typename Array1 , typename Array2 , typename Array3 > | |
void | cusp::assert_same_dimensions (const Array1 &array1, const Array2 &array2, const Array3 &array3) |
Assert dimensions of two arrays are equal. Throw invalid input exception if dimensions do not match. More... | |
template<typename Array1 , typename Array2 , typename Array3 , typename Array4 > | |
void | cusp::assert_same_dimensions (const Array1 &array1, const Array2 &array2, const Array3 &array3, const Array4 &array4) |
Assert dimensions of two arrays are equal. Throw invalid input exception if dimensions do not match. More... | |
void cusp::add | ( | const MatrixType1 & | A, |
const MatrixType2 & | B, | ||
MatrixType3 & | C | ||
) |
Compute the sum of two matrices.
MatrixType1 | Type of first matrix |
MatrixType2 | Type of second matrix |
MatrixType3 | Type of output matrix |
A | first input matrix |
B | second input matrix |
C | output matrix |
add
.void cusp::assert_is_valid_matrix | ( | const MatrixType & | matrix | ) |
Validate format of a given matrix and exit if invalid.
MatrixType | matrix container |
matrix | A matrix container (e.g. csr_matrix or coo_matrix ) |
void cusp::assert_same_dimensions | ( | const Array1 & | array1, |
const Array2 & | array2 | ||
) |
Assert dimensions of two arrays are equal. Throw invalid input exception if dimensions do not match.
Array1 | First array container type |
Array2 | Second array container type |
array1 | First array used in comparison |
array2 | Second array used in comparison |
void cusp::assert_same_dimensions | ( | const Array1 & | array1, |
const Array2 & | array2, | ||
const Array3 & | array3 | ||
) |
Assert dimensions of two arrays are equal. Throw invalid input exception if dimensions do not match.
Array1 | First array container type |
Array2 | Second array container type |
Array3 | Third array container type |
array1 | First array used in comparison |
array2 | Second array used in comparison |
array3 | Third array used in comparison |
void cusp::assert_same_dimensions | ( | const Array1 & | array1, |
const Array2 & | array2, | ||
const Array3 & | array3, | ||
const Array4 & | array4 | ||
) |
Assert dimensions of two arrays are equal. Throw invalid input exception if dimensions do not match.
Array1 | First array container type |
Array2 | Second array container type |
Array3 | Third array container type |
Array4 | Fourth array container type |
array1 | First array used in comparison |
array2 | Second array used in comparison |
array3 | Third array used in comparison |
array4 | Fourth array used in comparison |
size_t cusp::compute_max_entries_per_row | ( | const ArrayType & | row_offsets | ) |
Compute the maximum row length of a matrix.
ArrayType | Type of input row offsets |
row_offsets | row offsets of input matrix |
size_t cusp::compute_optimal_entries_per_row | ( | const ArrayType & | row_offsets, |
float | relative_speed = 3.0f , |
||
size_t | breakeven_threshold = 4096 |
||
) |
Compute the optimal number of entries per row of HYB matrix.
ArrayType | Type of input row offsets |
row_offsets | row offsets of input matrix |
relative_speed | Estimated performance difference between ELL and COO row storage schemes |
breakeven_threshold | Threshold value separating ELL and COO row classification |
void cusp::convert | ( | const SourceType & | src, |
DestinationType & | dst | ||
) |
Convert between matrix formats.
SourceType | Type of the input matrix to convert |
DestinationType | Type of the output matrix to create |
src | Input matrix to convert |
dst | Output matrix created by converting src to the specified format |
copy
void cusp::copy | ( | const SourceType & | src, |
DestinationType & | dst | ||
) |
Copy one array or matrix to another.
SourceType | Type of the input matrix to copy |
DestinationType | Type of the output matrix |
src | Input matrix to copy |
dst | Output matrix created by copying src to dst |
convert
size_t cusp::count_diagonals | ( | const size_t | num_rows, |
const size_t | num_cols, | ||
const ArrayType1 & | row_indices, | ||
const ArrayType2 & | column_indices | ||
) |
Count the number of occupied diagonals in the input matrix.
ArrayType1 | Type of input row indices |
ArrayType2 | Type of input column indices |
num_rows | Number of rows. |
num_cols | Number of columns. |
row_indices | row indices of input matrix |
column_indices | column indices of input matrix |
void cusp::counting_sort | ( | ArrayType & | keys, |
typename ArrayType::value_type | min, | ||
typename ArrayType::value_type | max | ||
) |
Use counting sort to order an array.
ArrayType | Type of input array |
keys | input of keys to sort |
min | minimum key in input array |
max | maximum key in input array |
counting_sort
.void cusp::counting_sort_by_key | ( | ArrayType1 & | keys, |
ArrayType2 & | vals, | ||
typename ArrayType1::value_type | min, | ||
typename ArrayType1::value_type | max | ||
) |
Use counting sort to order an array and permute an array of values.
ArrayType1 | Type of keys array |
ArrayType2 | Type of values array |
keys | input array of keys to sort |
vals | input array of values to permute |
min | minimum key in keys array |
max | maximum key in keys array |
counting_sort_by_key
.void cusp::elementwise | ( | const MatrixType1 & | A, |
const MatrixType2 & | B, | ||
MatrixType3 & | C, | ||
BinaryFunction | op | ||
) |
Perform transform operation on two matrices.
MatrixType1 | Type of first matrix |
MatrixType2 | Type of second matrix |
MatrixType3 | Type of output matrix |
BinaryFunction | Type of binary transform to apply |
A | first input matrix |
B | second input matrix |
C | output matrix |
op | binary transform to apply |
elementwise
.void cusp::extract_diagonal | ( | const MatrixType & | A, |
ArrayType & | output | ||
) |
Extract the main diagonal of a matrix.
MatrixType | Type of input matrix |
ArrayType | Type of input diagonal array |
A | The input matrix |
output | On return contains the main diagonal of A with zeros inserted for missing entries. |
void cusp::generalized_spgemm | ( | const LinearOperator & | A, |
const MatrixOrVector1 & | B, | ||
MatrixOrVector2 & | C, | ||
UnaryFunction | initialize, | ||
BinaryFunction1 | combine, | ||
BinaryFunction2 | reduce | ||
) |
Implements generalized matrix-matrix multiplication.
generalized
multiply can be used with dense and sparse matrices, and user-defined linear_operator
objects. This function compute nonzeros only for the entries present in the output matrix. Entries that are not specified in the output matrix are disregarded (annihilated). This specification significantly reduces the computational work corresponding to computing the sparsity of the output and performing unnecessary (combine, reduce) operations.
LinearOperator | Type of matrix |
MatrixOrVector1 | Type of second matrix |
MatrixOrVector2 | Type of output matrix |
UnaryFunction | Type of unary function to initialize RHS |
BinaryFunction1 | Type of binary function to combine entries |
BinaryFunction2 | Type of binary function to reduce entries |
A | first input matrix |
B | second input matrix |
C | output matrix |
The following code snippet demonstrates how to use generalized_spgemm
to compute a matrix-matrix product.
void cusp::generalized_spmv | ( | const LinearOperator & | A, |
const Vector1 & | x, | ||
const Vector2 & | y, | ||
Vector3 & | z, | ||
BinaryFunction1 | combine, | ||
BinaryFunction2 | reduce | ||
) |
Implements generalized matrix-vector multiplication.
generalized
multiply can be used with dense and sparse matrices, and user-defined linear_operator
objects.
LinearOperator | Type of first matrix |
Vector1 | Type of second input vector |
Vector2 | Type of third input vector |
Vector3 | Type of output vector |
A | input matrix |
x | input vector |
y | input vector |
z | output vector |
The following code snippet demonstrates how to use multiply
to compute a matrix-vector product.
void cusp::indices_to_offsets | ( | const IndexArray & | indices, |
OffsetArray & | offsets | ||
) |
Compress COO row indices to CSR row offsets.
IndexArray | Type of input row indices |
OffsetType | Type of input row offsets |
indices | The input row indices |
offsets | The output row offsets |
bool cusp::is_valid_matrix | ( | const MatrixType & | matrix | ) |
Validate format of a given matrix.
MatrixType | matrix container |
matrix | A matrix container (e.g. csr_matrix or coo_matrix ) |
true
if format is valid otherwise false
bool cusp::is_valid_matrix | ( | const MatrixType & | matrix, |
OutputStream & | ostream | ||
) |
Validate format of a given matrix.
MatrixType | matrix container |
OutputStream | stream type |
matrix | A matrix container (e.g. csr_matrix or coo_matrix ) |
ostream | Stream to which the validate stream should print |
true
if format is valid otherwise false
void cusp::multiply | ( | const LinearOperator & | A, |
const MatrixOrVector1 & | B, | ||
MatrixOrVector2 & | C | ||
) |
Implements matrix-matrix and matrix-vector multiplication.
multiply
can be used with dense matrices, sparse matrices, and user-defined linear_operator
objects.
LinearOperator | Type of first matrix |
MatrixOrVector1 | Type of second matrix or vector |
MatrixOrVector2 | Type of output matrix or vector |
A | input matrix |
B | input matrix or vector |
C | output matrix or vector |
The following code snippet demonstrates how to use multiply
to compute a matrix-vector product.
void cusp::multiply | ( | const LinearOperator & | A, |
const MatrixOrVector1 & | B, | ||
MatrixOrVector2 & | C, | ||
UnaryFunction | initialize, | ||
BinaryFunction1 | combine, | ||
BinaryFunction2 | reduce | ||
) |
Implements matrix-vector multiplication with custom combine and reduce functionality.
multiply
can be used with dense matrices, sparse matrices, and user-defined linear_operator
objects.
LinearOperator | Type of matrix |
MatrixOrVector1 | Type of second vector |
MatrixOrVector2 | Type of output vector |
UnaryFunction | Type of unary function to initialize RHS |
BinaryFunction1 | Type of binary function to combine entries |
BinaryFunction2 | Type of binary function to reduce entries |
A | input matrix |
B | input vector |
C | output vector |
The following code snippet demonstrates how to use multiply
to compute a matrix-vector product.
void cusp::offsets_to_indices | ( | const OffsetArray & | offsets, |
IndexArray & | indices | ||
) |
Expand CSR row offsets to COO row indices.
OffsetType | Type of input row offsets |
IndexArray | Type of input row indices |
offsets | The input row offsets |
indices | The output row indices |
void cusp::sort_by_row | ( | ArrayType1 & | row_indices, |
ArrayType2 & | column_indices, | ||
ArrayType3 & | values, | ||
typename ArrayType1::value_type | min_row = 0 , |
||
typename ArrayType1::value_type | max_row = 0 |
||
) |
Sort matrix indices by row.
ArrayType1 | Type of input matrix row indices |
ArrayType2 | Type of input matrix column indices |
ArrayType3 | Type of input matrix values |
row_indices | input matrix row indices |
column_indices | input matrix column indices |
values | input matrix values |
min_row | minimum row index |
max_row | maximum row index |
sort_by_row
.void cusp::sort_by_row_and_column | ( | ArrayType1 & | row_indices, |
ArrayType2 & | column_indices, | ||
ArrayType3 & | values, | ||
typename ArrayType1::value_type | min_row = 0 , |
||
typename ArrayType1::value_type | max_row = 0 , |
||
typename ArrayType2::value_type | min_col = 0 , |
||
typename ArrayType2::value_type | max_col = 0 |
||
) |
Sort matrix indices by row and column.
ArrayType1 | Type of input matrix row indices |
ArrayType2 | Type of input matrix column indices |
ArrayType3 | Type of input matrix values |
row_indices | input matrix row indices |
column_indices | input matrix column indices |
values | input matrix values |
min_row | minimum row index |
max_row | maximum row index |
min_col | minimum column index |
max_col | maximum column index |
sort_by_row_and_column
.void cusp::subtract | ( | const MatrixType1 & | A, |
const MatrixType2 & | B, | ||
MatrixType3 & | C | ||
) |
Compute the difference of two matrices.
MatrixType1 | Type of first matrix |
MatrixType2 | Type of second matrix |
MatrixType3 | Type of output matrix |
A | first input matrix |
B | second input matrix |
C | output matrix |
subtract
.void cusp::transpose | ( | const MatrixType1 & | A, |
MatrixType2 & | At | ||
) |
Transpose a matrix.
MatrixType1 | Type of input matrix to transpose |
MatrixType2 | Type of output matrix |
A | input matrix |
At | output matrix (transpose of A) |
transpose
.