19template<
typename ValueType,
typename IndexType>
31 const std::span<ValueType>& values,
32 const std::span<IndexType>& colIdxs,
33 const std::span<IndexType>& rowPtrs
35 : values_(values), colIdxs_(colIdxs), rowPtrs_(rowPtrs) {};
48 KOKKOS_INLINE_FUNCTION
49 ValueType&
entry(
const IndexType i,
const IndexType j)
const
51 const IndexType rowSize = rowPtrs_[i + 1] - rowPtrs_[i];
52 for (std::remove_const_t<IndexType> ic = 0; ic < rowSize; ++ic)
54 const IndexType localCol = rowPtrs_[i] + ic;
55 if (colIdxs_[localCol] == j)
57 return values_[localCol];
59 if (colIdxs_[localCol] > j)
break;
61 Kokkos::abort(
"Memory not allocated for CSR matrix component.");
62 return values_[values_.size()];
70 KOKKOS_INLINE_FUNCTION
71 ValueType&
entry(
const IndexType offset)
const {
return values_[offset]; }
77 std::tuple<std::span<ValueType>, std::span<IndexType>, std::span<IndexType>>
span()
79 return {values_, colIdxs_, rowPtrs_};
84 std::span<ValueType> values_;
85 std::span<IndexType> colIdxs_;
86 std::span<IndexType> rowPtrs_;
89template<
typename ValueType,
typename IndexType>
127 [[nodiscard]] IndexType
nRows()
const {
return static_cast<IndexType
>(rowPtrs_.
size()) - 1; }
133 [[nodiscard]] IndexType
nNonZeros()
const {
return static_cast<IndexType
>(values_.size()); }
139 [[nodiscard]] std::span<ValueType>
values() {
return values_.span(); }
145 [[nodiscard]] std::span<IndexType>
colIdxs() {
return colIdxs_.
span(); }
151 [[nodiscard]] std::span<IndexType>
rowPtrs() {
return rowPtrs_.
span(); }
157 [[nodiscard]]
const std::span<const ValueType>
values()
const {
return values_.span(); }
163 [[nodiscard]]
const std::span<const IndexType>
colIdxs()
const {
return colIdxs_.
span(); }
169 [[nodiscard]]
const std::span<const IndexType>
rowPtrs()
const {
return rowPtrs_.
span(); }
178 if (dstExec == values_.exec())
A class to contain the data and executors for a field and define some basic operations.
size_t size() const
Gets the size of the field.
Field< ValueType > copyToHost() const
Returns a copy of the field back to the host.
std::span< ValueType > span() &&=delete
Reference executor for serial CPU execution.
A helper class to allow easy read/write on all executors.
CSRMatrixSpan(const std::span< ValueType > &values, const std::span< IndexType > &colIdxs, const std::span< IndexType > &rowPtrs)
Constructor for CSRMatrixSpan.
KOKKOS_INLINE_FUNCTION ValueType & entry(const IndexType offset) const
Direct access to a value given the offset.
KOKKOS_INLINE_FUNCTION ValueType & entry(const IndexType i, const IndexType j) const
Retrieve a reference to the matrix element at position (i,j).
std::tuple< std::span< ValueType >, std::span< IndexType >, std::span< IndexType > > span()
Returns a structured binding of all containers.
~CSRMatrixSpan()=default
Default destructor.
CSRMatrixSpan< ValueType, IndexType > span()
Get a span representation of the matrix.
const Executor & exec() const
Get the executor associated with this matrix.
std::span< IndexType > colIdxs()
Get a span to the column indices array.
const std::span< const IndexType > colIdxs() const
Get a const span to the column indices array.
const std::span< const ValueType > values() const
Get a const span to the values array.
const std::span< const IndexType > rowPtrs() const
Get a const span to the row pointers array.
const CSRMatrixSpan< const ValueType, const IndexType > span() const
Get a const span representation of the matrix.
CSRMatrix< ValueType, IndexType > copyToHost() const
Copy the matrix to the host.
CSRMatrix(const Field< ValueType > &values, const Field< IndexType > &colIdxs, const Field< IndexType > &rowPtrs)
Constructor for CSRMatrix.
std::span< IndexType > rowPtrs()
Get a span to the row pointers array.
~CSRMatrix()=default
Default destructor.
IndexType nNonZeros() const
Get the number of non-zero values in the matrix.
CSRMatrix< ValueType, IndexType > copyToExecutor(Executor dstExec) const
Copy the matrix to another executor.
IndexType nRows() const
Get the number of rows in the matrix.
std::span< ValueType > values()
Get a span to the values array.
#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