Template Class CooMatrix

Class Documentation

template<typename RealT, typename IdxT>
class CooMatrix

Public Functions

CooMatrix(IdxT n, IdxT m, IdxT nnz)

basic constructor. It DOES NOT allocate any memory!

Parameters:
  • n[in] - number of rows

  • m[in] - number of columns

  • nnz_[in] - number of non-zeros

CooMatrix(IdxT n, IdxT m, IdxT nnz, IdxT **rows, IdxT **cols, RealT **vals, memory::MemorySpace memspace_src = memory::HOST, memory::MemorySpace memspace_dst = memory::HOST)

Hijacking constructor.

Parameters:
  • n[in]

  • m[in]

  • nnz_[in]

  • rows[inout]

  • cols[inout]

  • vals[inout]

  • memspace_src[in]

  • memspace_dst[in]

IdxT getNumRows() const

get number of matrix rows

Returns:

number of matrix rows.

IdxT getNumColumns() const

get number of matrix columns

Returns:

number of matrix columns.

IdxT getNnz() const

get number of non-zeros in the matrix.

Returns:

number of non-zeros.

int setDataPointers(IdxT *row_data, IdxT *col_data, RealT *val_data, memory::MemorySpace memspace)

Set the pointers for matrix row, column, value data.

Useful if interfacing with other codes - this function only assigns pointers, but it does not allocate nor copy anything. The data ownership flags would be set to false (default).

Parameters:
  • row_data[in] - pointer to row data (array of integers)

  • col_data[in] - pointer to column data (array of integers)

  • val_data[in] - pointer to value data (array of real numbers)

  • memspace[in] - memory space (HOST or DEVICE) of incoming data

Returns:

0 if successful, 1 if not.

int destroyMatrixData(memory::MemorySpace memspace)

destroy matrix data (HOST or DEVICE) if the matrix owns it (will attempt to destroy all three arrays).

Parameters:

memspace[in] - memory space (HOST or DEVICE) of incoming data

Returns:

0 if successful, -1 if not.

void print(std::ostream &file_out = std::cout, IdxT indexing_base = 0)

Prints matrix data.

Parameters:

out – - Output stream where the matrix data is printed

int syncData(memory::MemorySpace memspace_out)

Sync data in memspace with the updated memory space.

See also

CooMatrix::setUpdated

Parameters:

memspace – - memory space to be synced up (HOST or DEVICE)

Returns:

int - 0 if successful, error code otherwise

Pre:

The memory space other than memspace must be up-to-date. Otherwise, this function will return an error.

IdxT *getCsrRowData()

Sort COO entries by (row, col), merge duplicate entries, and build CSR row pointers.

Note

This function operates on host (CPU) data only.

Returns:

Pointer to CSR row pointer array