36template<
typename ValueType>
54 [&ptr,
size](
const auto& concreteExec)
55 { ptr = concreteExec.template alloc<ValueType>(
size); },
58 data_ =
static_cast<ValueType*
>(ptr);
75 : size_(
size), data_(nullptr), exec_(
exec)
79 [&ptr,
size](
const auto& concreteExec)
80 { ptr = concreteExec.template alloc<ValueType>(
size); },
83 data_ =
static_cast<ValueType*
>(ptr);
96 : size_(
size), data_(nullptr), exec_(
exec)
100 [&ptr,
size](
const auto& execu) { ptr = execu.template alloc<ValueType>(
size); }, exec_
102 data_ =
static_cast<ValueType*
>(ptr);
148 std::visit([
this](
const auto&
exec) {
exec.free(data_); }, exec_);
160 template<
typename func>
174 if (dstExec == exec_)
return *
this;
200 result.
size() == size_,
"Parsed Array size not the same as current field size"
232 NF_ASSERT(exec_ == rhs.exec_,
"Executors are not the same");
251 [
this, &ptr,
size](
const auto&
exec)
252 { ptr =
exec.template realloc<ValueType>(this->data_,
size); },
259 [&ptr,
size](
const auto&
exec) { ptr =
exec.template alloc<ValueType>(
size); },
263 data_ =
static_cast<ValueType*
>(ptr);
272 [[nodiscard]]
inline ValueType*
data() {
return data_; }
279 [[nodiscard]]
inline const ValueType*
data()
const {
return data_; }
307 [[nodiscard]]
inline bool empty()
const {
return size() == 0; }
377 [[nodiscard]]
inline std::pair<localIdx, localIdx>
range()
const
385 ValueType* data_ {
nullptr};
sizeType size() const
Returns the number of elements in the Array.
const ValueType * data() const
Returns a pointer to the underlying array data.
View< ValueType > view() &&=delete
Array< ValueType > copyToHost() const
Creates a host-resident copy of the Array.
void copyToHost(Array< ValueType > &result)
Copies the Array data to a host-resident Array.
View< ValueType > view(std::pair< localIdx, localIdx > range) &
Returns a view of a range of the Array.
std::pair< localIdx, localIdx > range() const
Returns the index range of the Array.
Array(Array< ValueType > &&rhs) noexcept
Move constructor.
Array< ValueType > copyToExecutor(Executor dstExec) const
Creates a copy of the Array on a specified executor.
View< const ValueType > view() const &
Returns a view of the Array data.
Array(const Executor &exec, sizeType size)
Creates an uninitialized Array with the given size on an executor.
label ssize() const
Returns the number of elements in the Array.
Array(const Executor &exec, const ValueType *in, sizeType size, Executor hostExec=SerialExecutor())
Creates an Array from existing data on the given executor.
void operator=(const ValueType &rhs)
Assigns a value to all elements of the Array.
const Array & operator[](const localIdx i) const =delete
View< const ValueType > view(std::pair< localIdx, localIdx > range) const &
Returns a view of a range of the Array.
bool empty() const
Checks whether the Array contains no elements.
const Executor & exec() const
Returns the executor associated with the Array.
View< const ValueType > view() const &&=delete
void resize(const sizeType size)
Resizes the Array.
Array(const Executor &exec, std::vector< ValueType > in)
Create an Array from a std::vector on a given executor.
Array & operator[](const localIdx i)=delete
Array(const Executor &exec, sizeType size, ValueType value)
Creates an Array with the given size and initializes all elements to a value.
~Array()
Destroy the Array object.
Array(const Executor &exec, const Array< ValueType > &in)
Creates a copy of an Array on the specified executor.
Array(const Array< ValueType > &rhs)
Creates a copy of another Array on the same executor.
View< ValueType > view(std::pair< localIdx, localIdx > range) &&=delete
void operator=(const Array< ValueType > &rhs)
Copies the contents of another Array.
View< const ValueType > view(std::pair< localIdx, localIdx > range) const &&=delete
void apply(func f)
Applies a function to each element of the Array.
ValueType * data()
Returns a pointer to the underlying array data.
Reference executor for serial CPU execution.
#define NF_ERROR_EXIT(message)
Macro for printing an error message and aborting the program.
#define NF_ASSERT(condition, message)
Macro for asserting a condition and printing an error message if the condition is false.
#define NF_DEBUG_ASSERT(condition, message)
Macro for asserting a condition and printing an error message if the condition is false (only in debu...
auto deepCopyVisitor(sizeType size, const ValueType *srcPtr, ValueType *dstPtr)
A helper function to simplify the common pattern of copying between and to executor.
Integer types used throughout NeoN.
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
localIdx toLocalIdx(sizeType value)
void map(ContType< ValueType > &cont, const Inner inner, std::pair< localIdx, localIdx > range={0, 0})
Map a field using a specific executor.
void validateRange(std::pair< localIdx, localIdx > range, sizeType size)
void setContainer(ContType< ValueType > &cont, const View< const std::type_identity_t< ValueType > > view, std::pair< localIdx, localIdx > range={0, 0})
Set the container with a view of values using a specific executor.
void fill(ContType< ValueType > &cont, const std::type_identity_t< ValueType > value, std::pair< localIdx, localIdx > range={0, 0})
Fill the field with a vector value using a specific executor.