23template<
typename IndexType>
26 IndexType finalValue = 0;
27 auto inSpan = intervals.
span();
28 auto offsSpan = offsets.
span();
34 update += inSpan[i - 1];
50template<
typename ValueType,
typename IndexType = NeoFOAM::localIdx>
71 KOKKOS_INLINE_FUNCTION
72 Kokkos::pair<IndexType, IndexType>
bounds(std::size_t segI)
const
74 return Kokkos::pair<IndexType, IndexType> {
segments[segI],
segments[segI + 1]};
83 KOKKOS_INLINE_FUNCTION
84 Kokkos::pair<IndexType, IndexType>
range(std::size_t segI)
const
86 return Kokkos::pair<IndexType, IndexType> {
98 KOKKOS_INLINE_FUNCTION std::span<ValueType>
span(std::size_t segI)
const
100 auto [start, length] =
range(segI);
101 return values.subspan(start, length);
110 KOKKOS_INLINE_FUNCTION
120template<
typename ValueType,
typename IndexType>
142 : values_(intervals.
exec(), 0),
143 segments_(intervals.
exec(), intervals.
size() + 1, IndexType(0))
172 size_t size()
const {
return values_.size(); }
197 [[nodiscard]] std::pair<std::span<ValueType>, std::span<IndexType>>
spans() &
199 return {values_.span(), segments_.
span()};
203 [[nodiscard]] std::pair<std::span<ValueType>, std::span<IndexType>>
spans() && =
delete;
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.
const Executor & exec() const
Gets the executor associated with the field.
std::span< ValueType > span() &&=delete
A class representing a segment of indices.
KOKKOS_INLINE_FUNCTION IndexType operator[](std::size_t i) const
Access an element of the segments.
std::span< ValueType > values
A span with the values.
KOKKOS_INLINE_FUNCTION Kokkos::pair< IndexType, IndexType > bounds(std::size_t segI) const
Get the bounds of a segment.
KOKKOS_INLINE_FUNCTION std::span< ValueType > span(std::size_t segI) const
Get a subspan of values corresponding to a segment.
std::span< IndexType > segments
A span of indices representing the segments.
KOKKOS_INLINE_FUNCTION Kokkos::pair< IndexType, IndexType > range(std::size_t segI) const
Get the range, ie. [start,end), of a segment.
Data structure that stores a segmented fields or a vector of vectors.
const Executor & exec() const
Get the executor associated with the segmented field.
SegmentedFieldView< ValueType, IndexType > view() &
get a view of the segmented field
std::pair< std::span< ValueType >, std::span< IndexType > > spans() &
get the combined value and range spans of the segmented field
const Field< ValueType > & values() const
const Field< IndexType > & segments() const
SegmentedField(const Field< ValueType > &values, const Field< IndexType > &segments)
Constructor to create a segmentedField from values and the segments.
SegmentedFieldView< ValueType, IndexType > view() &&=delete
std::pair< std::span< ValueType >, std::span< IndexType > > spans() &&=delete
size_t numSegments() const
Get the number of segments in the segmented field.
SegmentedField(const Executor &exec, size_t size, size_t numSegments)
Create a segmented field with a given size and number of segments.
SegmentedField(const Field< IndexType > &intervals)
size_t size() const
Get the size of the segmented field.
#define NF_ASSERT_EQUAL(a, b)
Macro for asserting that two values are equal and printing an error message if they are not.
#define NF_ASSERT(condition, message)
Macro for asserting a condition and printing an error message if the condition is false.
IndexType segmentsFromIntervals(const Field< IndexType > &intervals, Field< IndexType > &offsets)
Compute segment offsets from an input field corresponding to lengths by computing a prefix sum.
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
void parallelScan(const Executor &exec, std::pair< size_t, size_t > range, Kernel kernel)