NeoN
A framework for CFD software
Loading...
Searching...
No Matches
NeoN::Array< ValueType > Class Template Reference

An executor-aware contiguous container for structural and indexing data. More...

#include <array.hpp>

Public Types

using ArrayValueType = ValueType

Public Member Functions

 Array (const Executor &exec, sizeType size)
 Creates an uninitialized Array with the given size on an executor.
 Array (const Executor &exec, const ValueType *in, sizeType size, Executor hostExec=SerialExecutor())
 Creates an Array from existing data on the given executor.
 Array (const Executor &exec, sizeType size, ValueType value)
 Creates an Array with the given size and initializes all elements to a value.
 Array (const Executor &exec, std::vector< ValueType > in)
 Create an Array from a std::vector on a given executor.
 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.
 Array (Array< ValueType > &&rhs) noexcept
 Move constructor.
 ~Array ()
 Destroy the Array object.
template<typename func>
void apply (func f)
 Applies a function to each element of the Array.
Array< ValueType > copyToExecutor (Executor dstExec) const
 Creates a copy of the Array on a specified executor.
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.
Array & operator[] (const localIdx i)=delete
const Array & operator[] (const localIdx i) const =delete
void operator= (const ValueType &rhs)
 Assigns a value to all elements of the Array.
void operator= (const Array< ValueType > &rhs)
 Copies the contents of another Array.
void resize (const sizeType size)
 Resizes the Array.
ValueType * data ()
 Returns a pointer to the underlying array data.
const ValueType * data () const
 Returns a pointer to the underlying array data.
const Executor & exec () const
 Returns the executor associated with the Array.
sizeType size () const
 Returns the number of elements in the Array.
label ssize () const
 Returns the number of elements in the Array.
bool empty () const
 Checks whether the Array contains no elements.
View< ValueType > view () &&=delete
View< const ValueType > view () const &&=delete
View< ValueType > view () &
 Returns a view of the Array data.
View< const ValueType > view () const &
 Returns a view of the Array data.
View< ValueType > view (std::pair< localIdx, localIdx > range) &&=delete
View< const ValueType > view (std::pair< localIdx, localIdx > range) const &&=delete
View< ValueType > view (std::pair< localIdx, localIdx > range) &
 Returns a view of a range of the Array.
View< const ValueType > view (std::pair< localIdx, localIdx > range) const &
 Returns a view of a range of the Array.
std::pair< localIdx, localIdx > range () const
 Returns the index range of the Array.

Detailed Description

template<typename ValueType>
class NeoN::Array< ValueType >

An executor-aware contiguous container for structural and indexing data.

Array is intended for data that is primarily used as a generic collection, particularly for structural, indexing, or other non-arithmetic data.

Unlike Vector, Array does not primarily model numerical quantities or provide vector-style arithmetic semantics. Use Array when the primary purpose of the data is storage and indexed access rather than numerical operations.

Template Parameters
ValueTypeThe type of the elements stored in the array.

Definition at line 37 of file array.hpp.

Member Typedef Documentation

◆ ArrayValueType

template<typename ValueType>
using NeoN::Array< ValueType >::ArrayValueType = ValueType

Definition at line 42 of file array.hpp.

Constructor & Destructor Documentation

◆ Array() [1/7]

template<typename ValueType>
NeoN::Array< ValueType >::Array ( const Executor & exec,
sizeType size )
inline

Creates an uninitialized Array with the given size on an executor.

Parameters
execExecutor on which the array data is allocated.
sizeNumber of elements in the array.

Definition at line 50 of file array.hpp.

◆ Array() [2/7]

template<typename ValueType>
NeoN::Array< ValueType >::Array ( const Executor & exec,
const ValueType * in,
sizeType size,
Executor hostExec = SerialExecutor() )
inline

Creates an Array from existing data on the given executor.

Parameters
execExecutor on which the array data is allocated.
inPointer to the source data.
sizeNumber of elements to copy.
hostExecExecutor on which the source data is located.

Definition at line 69 of file array.hpp.

◆ Array() [3/7]

template<typename ValueType>
NeoN::Array< ValueType >::Array ( const Executor & exec,
sizeType size,
ValueType value )
inline

Creates an Array with the given size and initializes all elements to a value.

Parameters
execExecutor on which the array data is allocated.
sizeNumber of elements in the array.
valueValue used to initialize all elements.

Definition at line 95 of file array.hpp.

◆ Array() [4/7]

template<typename ValueType>
NeoN::Array< ValueType >::Array ( const Executor & exec,
std::vector< ValueType > in )
inline

Create an Array from a std::vector on a given executor.

Parameters
execExecutor on which the array data is allocated
instd::vector containing the values to copy into the array

Definition at line 111 of file array.hpp.

◆ Array() [5/7]

template<typename ValueType>
NeoN::Array< ValueType >::Array ( const Executor & exec,
const Array< ValueType > & in )
inline

Creates a copy of an Array on the specified executor.

Parameters
execExecutor on which the new array is allocated.
inArray to copy.

Definition at line 120 of file array.hpp.

◆ Array() [6/7]

template<typename ValueType>
NeoN::Array< ValueType >::Array ( const Array< ValueType > & rhs)
inline

Creates a copy of another Array on the same executor.

Parameters
rhsArray to copy from.

Definition at line 129 of file array.hpp.

◆ Array() [7/7]

template<typename ValueType>
NeoN::Array< ValueType >::Array ( Array< ValueType > && rhs)
inlinenoexcept

Move constructor.

Parameters
rhsArray whose resources are transferred to the new Array.

Definition at line 137 of file array.hpp.

◆ ~Array()

template<typename ValueType>
NeoN::Array< ValueType >::~Array ( )
inline

Destroy the Array object.

Definition at line 146 of file array.hpp.

Member Function Documentation

◆ apply()

template<typename ValueType>
template<typename func>
void NeoN::Array< ValueType >::apply ( func f)
inline

Applies a function to each element of the Array.

Parameters
fFunction or functor applied to the array elements.
Note
The function should be compatible with execution by Kokkos. Ideally, it should be Kokkos lambda.

Definition at line 161 of file array.hpp.

◆ copyToExecutor()

template<typename ValueType>
Array< ValueType > NeoN::Array< ValueType >::copyToExecutor ( Executor dstExec) const
inlinenodiscard

Creates a copy of the Array on a specified executor.

Parameters
dstExecExecutor on which the copied array is allocated.
Returns
A copy of this Array on dstExec.

Definition at line 172 of file array.hpp.

◆ copyToHost() [1/2]

template<typename ValueType>
Array< ValueType > NeoN::Array< ValueType >::copyToHost ( ) const
inlinenodiscard

Creates a host-resident copy of the Array.

Returns
A copy of this Array allocated on the serial executor.

Definition at line 187 of file array.hpp.

◆ copyToHost() [2/2]

template<typename ValueType>
void NeoN::Array< ValueType >::copyToHost ( Array< ValueType > & result)
inline

Copies the Array data to a host-resident Array.

Parameters
resultDestination Array. Its size must match the source Array.
Warning
An error is raised if result does not have the same size as this Array.

Definition at line 197 of file array.hpp.

◆ data() [1/2]

template<typename ValueType>
ValueType * NeoN::Array< ValueType >::data ( )
inlinenodiscard

Returns a pointer to the underlying array data.

Returns
Pointer to the first element.

Definition at line 272 of file array.hpp.

◆ data() [2/2]

template<typename ValueType>
const ValueType * NeoN::Array< ValueType >::data ( ) const
inlinenodiscard

Returns a pointer to the underlying array data.

Returns
Pointer to the first element.

Definition at line 279 of file array.hpp.

◆ empty()

template<typename ValueType>
bool NeoN::Array< ValueType >::empty ( ) const
inlinenodiscard

Checks whether the Array contains no elements.

Returns
True if the Array is empty, otherwise false.

Definition at line 307 of file array.hpp.

◆ exec()

template<typename ValueType>
const Executor & NeoN::Array< ValueType >::exec ( ) const
inlinenodiscard

Returns the executor associated with the Array.

Returns
Reference to the Array's executor.

Definition at line 286 of file array.hpp.

◆ operator=() [1/2]

template<typename ValueType>
void NeoN::Array< ValueType >::operator= ( const Array< ValueType > & rhs)
inline

Copies the contents of another Array.

Parameters
rhsArray to copy from.
Warning
The source and destination Arrays must use the same executor. The destination is resized if necessary.

Definition at line 230 of file array.hpp.

◆ operator=() [2/2]

template<typename ValueType>
void NeoN::Array< ValueType >::operator= ( const ValueType & rhs)
inline

Assigns a value to all elements of the Array.

Parameters
rhsValue assigned to each element.

Definition at line 216 of file array.hpp.

◆ operator[]() [1/2]

template<typename ValueType>
const Array & NeoN::Array< ValueType >::operator[] ( const localIdx i) const
delete

◆ operator[]() [2/2]

template<typename ValueType>
Array & NeoN::Array< ValueType >::operator[] ( const localIdx i)
delete

◆ range()

template<typename ValueType>
std::pair< localIdx, localIdx > NeoN::Array< ValueType >::range ( ) const
inlinenodiscard

Returns the index range of the Array.

Returns
The half-open index range [0, size()).

Definition at line 377 of file array.hpp.

◆ resize()

template<typename ValueType>
void NeoN::Array< ValueType >::resize ( const sizeType size)
inline

Resizes the Array.

Parameters
sizeNew number of elements.

Definition at line 245 of file array.hpp.

◆ size()

template<typename ValueType>
sizeType NeoN::Array< ValueType >::size ( ) const
inlinenodiscard

Returns the number of elements in the Array.

Returns
Number of elements.

Definition at line 293 of file array.hpp.

◆ ssize()

template<typename ValueType>
label NeoN::Array< ValueType >::ssize ( ) const
inlinenodiscard

Returns the number of elements in the Array.

Returns
Number of elements.

Definition at line 300 of file array.hpp.

◆ view() [1/8]

template<typename ValueType>
View< ValueType > NeoN::Array< ValueType >::view ( ) &
inlinenodiscard

Returns a view of the Array data.

Returns
Non-owning view of the Array data.

Definition at line 320 of file array.hpp.

◆ view() [2/8]

template<typename ValueType>
View< ValueType > NeoN::Array< ValueType >::view ( ) &&
delete

◆ view() [3/8]

template<typename ValueType>
View< const ValueType > NeoN::Array< ValueType >::view ( ) const &
inlinenodiscard

Returns a view of the Array data.

Returns
Non-owning view of the Array data.

Definition at line 327 of file array.hpp.

◆ view() [4/8]

template<typename ValueType>
View< const ValueType > NeoN::Array< ValueType >::view ( ) const &&
delete

◆ view() [5/8]

template<typename ValueType>
View< ValueType > NeoN::Array< ValueType >::view ( std::pair< localIdx, localIdx > range) &
inlinenodiscard

Returns a view of a range of the Array.

Parameters
rangeHalf-open range of elements to include in the view.
Returns
Non-owning view of the specified range.
Precondition
range.first <= range.second
range.second <= size()
Note
The returned view does not own the underlying data. The Array must remain alive when the view is in use.

Definition at line 350 of file array.hpp.

◆ view() [6/8]

template<typename ValueType>
View< ValueType > NeoN::Array< ValueType >::view ( std::pair< localIdx, localIdx > range) &&
nodiscarddelete

◆ view() [7/8]

template<typename ValueType>
View< const ValueType > NeoN::Array< ValueType >::view ( std::pair< localIdx, localIdx > range) const &
inlinenodiscard

Returns a view of a range of the Array.

Parameters
rangeHalf-open range of elements to include in the view.
Returns
Non-owning view of the specified range.

Definition at line 364 of file array.hpp.

◆ view() [8/8]

template<typename ValueType>
View< const ValueType > NeoN::Array< ValueType >::view ( std::pair< localIdx, localIdx > range) const &&
nodiscarddelete

The documentation for this class was generated from the following file: