COO Matrix

template<Number T>
class COOMatrix : public HighFM::MatrixBase<COOMatrix<T>>

A sparse matrix stored in the COOrdinate format, i.e., each nonzero is store as a triplet (row, col, val). The main purpose of the COOMatrix is to faciliate the construction of sparse matrix, which is later convert to a more convenient format (e.g., CSRMatrix) for evaluating arithmetic expressions.

Warning

No arithmetic operation are supported for the coordinate format.

Warning

When converting to another sparse matrix type, the nonzero entries must be sorted by row, and then by column. It also must not have duplicated nonzero entries (i.e., there is no duplicated entry at the (row, col) location).

Template Parameters:

T – Datatype used for storing the value of the nonzero element.

Public Functions

COOMatrix()

Creates an empty COOMatrix.

COOMatrix(index_t nrows, index_t ncols)

Creates an empty COOMatrix with dimensions nrows x ncols.

Parameters:
  • nrows[in] number of rows

  • ncols[in] number of columns

COOMatrix(index_t nrows, index_t ncols, index_t nnz)

Creates an empty COOMatrix with dimensions nrows x ncols. Reserve space of nnz elements.

Parameters:
  • nrows[in] number of rows

  • ncols[in] number of columns

  • nnz[in] number of nonzeros

COOMatrix(const COOMatrix &other)

Creates a COOMatrix from an other COOMatrix.

Parameters:

other[in] another COOMatrix to use as the data source.

COOMatrix(COOMatrix &&other)

Creates a new COOMatrix and then moves the content from an other COOMatrix.

Parameters:

other[in] another COOMatrix to use as the data source.

template<template<typename, typename> typename S>
COOMatrix(const CSRMatrix<T, Host, S> &csr)

Creates a COOMatrix from a CSRMatrix.

Parameters:

csr[in] a COOMatrix to use as the data source.

virtual ~COOMatrix() = default

Default destructor.

COOMatrix &operator=(const COOMatrix &other)

Copies the content from an other COOMatrix.

Parameters:

other[in] another COOMatrix to use as the data source.

Returns:

*this.

COOMatrix &operator=(COOMatrix &&other) noexcept

Moves the content from an other COOMatrix to this container.

Parameters:

other[in] another COOMatrix to use as the data source.

Returns:

*this.

template<template<typename, typename> typename S>
COOMatrix &operator=(const CSRMatrix<T, Host, S> &csr)

Copies the content from a CSRMatrix.

Parameters:

csr[in] a COOMatrix to use as the data source.

Returns:

*this.

Array<COOEntry<T>, Host> &triplets()
Returns:

The underlying container that stores the nonzero entries.

const Array<COOEntry<T>, Host> &triplets() const
Returns:

The underlying container that stores the nonzero entries.

COOEntry<T> &operator()(index_t idx)

Accesses the nonzero element at (idx) position.

Returns:

A reference to the value of the requested element.

COOEntry<T> operator()(index_t idx) const

Accesses the nonzero element at (idx) position.

Returns:

A reference to the value of the requested element.

index_t rows() const noexcept
Returns:

The number of rows in the COOMatrix.

index_t cols() const noexcept
Returns:

The number of columns in the COOMatrix

index_t size() const noexcept
Returns:

The number of nonzero entries in the COOMatrix.

void reserve(index_t nonzeros)

Reserves space in memory for nonzeros elements.

Parameters:

nonzeros[in] reserved size.

void clear() noexcept

Clears all the nonzero entries of the COOMatrix. This routine does not change the number of rows and columns of the matrix.

void resize(index_t nrows, index_t ncols)

Resizes the COOMatrix, changing the number of rows and columns to nrows and cols, respectively.

Parameters:
  • nrows[in] number of rows.

  • ncols[in] number of columns.

void sort()

Sorts the nonzero entries in the COOMatrix such that they are order by row and then by column.

void push_back(COOEntry<T> entry)

Inserts a nonzero element at the end of the COOMatrix. This automatically expand the container as needed.

Parameters:

entry[in] nonzero to be inserted

void swap(COOMatrix &other) noexcept

Swaps the COOMatrix content with other, including any memory allocation (if applicable).

Parameters:

other[inout] another COOMatrix to exchange content with.