19template<
typename ValueType,
typename IndexType>
46 KOKKOS_INLINE_FUNCTION
47 ValueType&
entry(
const IndexType i,
const IndexType j)
const
50 for (std::remove_const_t<IndexType> ic = 0; ic < rowSize; ++ic)
52 const IndexType localCol =
rowOffs[i] + ic;
57 if (
colIdxs[localCol] > j)
break;
59 Kokkos::abort(
"Memory not allocated for CSR matrix component.");
68 KOKKOS_INLINE_FUNCTION
69 ValueType&
entry(
const IndexType offset)
const {
return values[offset]; }
82template<
typename ValueType,
typename IndexType>
122 [[nodiscard]] IndexType
nRows()
const
124 return static_cast<IndexType
>(rowOffs_.
size())
125 -
static_cast<IndexType
>(
static_cast<bool>(rowOffs_.
size()));
132 [[nodiscard]] IndexType
nNonZeros()
const {
return static_cast<IndexType
>(values_.size()); }
177 if (dstExec == values_.exec())
Reference executor for serial CPU execution.
A class to contain the data and executors for a field and define some basic operations.
localIdx size() const
Gets the size of the field.
const Executor & exec() const
Gets the executor associated with the field.
View< ValueType > view() &&=delete
Vector< ValueType > copyToHost() const
Returns a copy of the field back to the host.
Sparse matrix class with compact storage by row (CSR) format.
IndexType nNonZeros() const
Get the number of non-zero values in the matrix.
const Vector< IndexType > & rowPtrs() const
Get a const span to the row pointers array.
const Vector< ValueType > & values() const
Get a const span to the values array.
Vector< IndexType > & colIdxs()
Get a span to the column indices array.
const Executor & exec() const
Get the executor associated with this matrix.
const CSRMatrixView< const ValueType, const IndexType > view() const
Get a const view representation of the matrix's data.
const Vector< IndexType > & colIdxs() const
Get a const span to the column indices array.
IndexType nRows() const
Get the number of rows in the matrix.
Vector< IndexType > & rowPtrs()
Get a span to the row pointers array.
Vector< ValueType > & values()
Get a span to the values array.
CSRMatrix< ValueType, IndexType > copyToHost() const
Copy the matrix to the host.
CSRMatrix(const Executor exec)
CSRMatrix(const Vector< ValueType > &values, const Vector< IndexType > &colIdxs, const Vector< IndexType > &rowOffs)
Constructor for CSRMatrix.
CSRMatrix< ValueType, IndexType > copyToExecutor(Executor dstExec) const
Copy the matrix to another executor.
CSRMatrixView< ValueType, IndexType > view()
Get a view representation of the matrix's data.
~CSRMatrix()=default
Default destructor.
#define NF_ASSERT(condition, message)
Macro for asserting a condition and printing an error message if the condition is false.
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
A view struct to allow easy read/write on all executors.
View< ValueType > values
View to the values of the CSR matrix.
View< IndexType > colIdxs
View to the column indices of the CSR matrix.
CSRMatrixView(const View< ValueType > &valueView, const View< IndexType > &colIdxsView, const View< IndexType > &rowOffsView)
Constructor for CSRMatrixView.
KOKKOS_INLINE_FUNCTION ValueType & entry(const IndexType i, const IndexType j) const
Retrieve a reference to the matrix element at position (i,j).
~CSRMatrixView()=default
Default destructor.
View< IndexType > rowOffs
View to the row offsets for the CSR matrix.
KOKKOS_INLINE_FUNCTION ValueType & entry(const IndexType offset) const
Direct access to a value given the offset.