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

An executor-aware contiguous container for numerical data with vector-style arithmetic semantics. More...

#include <vector.hpp>

Public Types

using VectorValueType = ValueType

Public Member Functions

 Vector (const Executor &exec, sizeType size)
 Creates an uninitialized Vector with the given size on an executor.
 Vector (const Executor &exec, const ValueType *in, sizeType size, Executor hostExec=SerialExecutor())
 Creates a Vector with the given size from existing data on an executor.
 Vector (const Executor &exec, sizeType size, ValueType value)
 Creates a Vector with the given size and initializes all elements to a value.
 Vector (const Executor &exec, std::vector< ValueType > in)
 Creates a Vector from a std::vector on the given executor.
 Vector (const Executor &exec, const Vector< ValueType > &in)
 Creates a copy of another Vector on the specified executor.
 Vector (const Vector< ValueType > &rhs)
 Copy constructor.
 Vector (Vector< ValueType > &&rhs) noexcept
 Move constructor.
 ~Vector ()
 Destroys the Vector object.
template<typename func>
void apply (func f)
 Applies a function to the elements of the Vector.
Vector< ValueType > copyToExecutor (Executor dstExec) const
 Creates a copy of the Vector on the specified executor.
Vector< ValueType > copyToHost () const
 Creates a host-resident copy of the Vector.
void copyToHost (Vector< ValueType > &result)
 Copies the Vector data to a host-resident Vector.
ValueType & operator[] (const localIdx i)=delete
 Host-side element access is intentionally disabled.
const ValueType & operator[] (const localIdx i) const =delete
void operator= (const ValueType &rhs)
 Assigns a value to every element of the Vector.
void operator= (const Vector< ValueType > &rhs)
 Assigns the contents of another Vector.
Vector< ValueType > & operator= (Vector< ValueType > &&rhs) noexcept
 Move-assignment operator — transfers ownership of the data buffer.
Vector< ValueType > & operator+= (const Vector< ValueType > &rhs)
 Adds another Vector element-wise.
Vector< ValueType > & operator-= (const Vector< ValueType > &rhs)
 Subtracts another Vector element-wise.
Vector< ValueType > operator* (const Vector< ValueType > &rhs)
 Multiplies two Vectors element-wise.
Vector< ValueType > operator* (const scalar rhs)
 Multiplies every element of the Vector by a scalar.
Vector< ValueType > & operator*= (const Vector< ValueType > &rhs)
 Multiplies this Vector element-wise by another Vector.
Vector< ValueType > & operator*= (const scalar rhs)
 Multiplies every element of the Vector by a scalar.
void resize (const sizeType size)
 Resizes the Vector.
ValueType * data ()
 Returns a pointer to the underlying Vector data.
const ValueType * data () const
 Returns a pointer to the underlying Vector data.
ValueType * begin ()
 Returns a pointer to the first element of the Vector.
const ValueType * begin () const
 Returns a const pointer to the first element of the Vector.
ValueType * end ()
 Returns a pointer one past the last element of the Vector.
const ValueType * end () const
 Returns a const pointer one past the last element of the Vector.
const Executor & exec () const
 Returns the executor associated with the Vector.
sizeType size () const
 Returns the number of elements in the Vector.
label ssize () const
 Returns the number of elements as a label.
bool empty () const
 Checks whether the Vector contains no elements.
View< ValueType > view () &&=delete
 Prevents creating a View from a temporary Vector.
View< const ValueType > view () const &&=delete
View< ValueType > view () &
 Returns a non-owning view of the Vector data.
View< const ValueType > view () const &
 Returns a read-only, non-owning view of the Vector data.
View< ValueType > view (std::pair< localIdx, localIdx > range) &&=delete
 Prevents creating a view of a temporary Vector.
View< const ValueType > view (std::pair< localIdx, localIdx > range) const &&=delete
View< ValueType > view (std::pair< localIdx, localIdx > range) &
 Returns a non-owning view of a range of the Vector.
View< const ValueType > view (std::pair< localIdx, localIdx > range) const &
 Returns a read-only, non-owning view of a range of the Vector.
std::pair< localIdx, localIdx > range () const
 Returns the index range of the Vector.

Detailed Description

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

An executor-aware contiguous container for numerical data with vector-style arithmetic semantics.

Vector is intended for numerical quantities for which arithmetic operations on the elements or on the vector as a whole are meaningful.

Vector provides operations for performing arithmetic on its stored values. Use Vector when the numerical meaning of the data and its arithmetic operations are an important part of its interface.

For structural, indexing, or other non-arithmetic data, use Array instead.

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

Definition at line 39 of file vector.hpp.

Member Typedef Documentation

◆ VectorValueType

template<typename ValueType>
using NeoN::Vector< ValueType >::VectorValueType = ValueType

Definition at line 44 of file vector.hpp.

Constructor & Destructor Documentation

◆ Vector() [1/7]

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

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

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

◆ Vector() [2/7]

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

Creates a Vector with the given size from existing data on an executor.

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

◆ Vector() [3/7]

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

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

Parameters
execExecutor on which the Vector data is allocated.
sizeNumber of elements in the Vector.
valueValue used to initialize every element.

◆ Vector() [4/7]

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

Creates a Vector from a std::vector on the given executor.

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

◆ Vector() [5/7]

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

Creates a copy of another Vector on the specified executor.

Parameters
execExecutor on which the new Vector is allocated.
inVector to copy.

◆ Vector() [6/7]

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

Copy constructor.

Parameters
rhsVector to copy from.

◆ Vector() [7/7]

template<typename ValueType>
NeoN::Vector< ValueType >::Vector ( Vector< ValueType > && rhs)
noexcept

Move constructor.

Parameters
rhsVector whose resources are transferred to the new Vector.

◆ ~Vector()

template<typename ValueType>
NeoN::Vector< ValueType >::~Vector ( )

Destroys the Vector object.

Member Function Documentation

◆ apply()

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

Applies a function to the elements of the Vector.

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

Definition at line 122 of file vector.hpp.

◆ begin() [1/2]

template<typename ValueType>
ValueType * NeoN::Vector< ValueType >::begin ( )
inlinenodiscard

Returns a pointer to the first element of the Vector.

Returns
Pointer to the first element.

Definition at line 297 of file vector.hpp.

◆ begin() [2/2]

template<typename ValueType>
const ValueType * NeoN::Vector< ValueType >::begin ( ) const
inlinenodiscard

Returns a const pointer to the first element of the Vector.

Returns
Const pointer to the first element.

Definition at line 304 of file vector.hpp.

◆ copyToExecutor()

template<typename ValueType>
Vector< ValueType > NeoN::Vector< ValueType >::copyToExecutor ( Executor dstExec) const
nodiscard

Creates a copy of the Vector on the specified executor.

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

◆ copyToHost() [1/2]

template<typename ValueType>
Vector< ValueType > NeoN::Vector< ValueType >::copyToHost ( ) const
nodiscard

Creates a host-resident copy of the Vector.

Returns
A copy of this Vector allocated on the host executor.

◆ copyToHost() [2/2]

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

Copies the Vector data to a host-resident Vector.

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

◆ data() [1/2]

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

Returns a pointer to the underlying Vector data.

Returns
Pointer to the first element of the Vector.

Definition at line 283 of file vector.hpp.

◆ data() [2/2]

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

Returns a pointer to the underlying Vector data.

Returns
Const pointer to the first element of the Vector.

Definition at line 290 of file vector.hpp.

◆ empty()

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

Checks whether the Vector contains no elements.

Returns
True if the Vector is empty, otherwise false.

Definition at line 346 of file vector.hpp.

◆ end() [1/2]

template<typename ValueType>
ValueType * NeoN::Vector< ValueType >::end ( )
inlinenodiscard

Returns a pointer one past the last element of the Vector.

Returns
Pointer one past the last element.

Definition at line 311 of file vector.hpp.

◆ end() [2/2]

template<typename ValueType>
const ValueType * NeoN::Vector< ValueType >::end ( ) const
inlinenodiscard

Returns a const pointer one past the last element of the Vector.

Returns
Const pointer one past the last element.

Definition at line 318 of file vector.hpp.

◆ exec()

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

Returns the executor associated with the Vector.

Returns
Reference to the Vector's executor.

Definition at line 325 of file vector.hpp.

◆ operator*() [1/2]

template<typename ValueType>
Vector< ValueType > NeoN::Vector< ValueType >::operator* ( const scalar rhs)
nodiscard

Multiplies every element of the Vector by a scalar.

Parameters
rhsScalar multiplier.
Returns
A Vector containing the scaled values.
Note
This operation is available only for ValueType combinations for which multiplication by scalar is well-defined. Types with ambiguous multiplication semantics, such as vec3, are excluded. See https://eel.is/c++draft/expr.prim.req for information on C++ requires-expressions.

◆ operator*() [2/2]

template<typename ValueType>
Vector< ValueType > NeoN::Vector< ValueType >::operator* ( const Vector< ValueType > & rhs)
nodiscard

Multiplies two Vectors element-wise.

Parameters
rhsVector to multiply with this Vector.
Returns
A Vector containing the element-wise product.
Note
This operation is available only for ValueType combinations for which element-wise multiplication is well-defined. Types with ambiguous multiplication semantics, such as vec3, are excluded. See https://eel.is/c++draft/expr.prim.req for information on C++ requires-expressions.

◆ operator*=() [1/2]

template<typename ValueType>
Vector< ValueType > & NeoN::Vector< ValueType >::operator*= ( const scalar rhs)

Multiplies every element of the Vector by a scalar.

Parameters
rhsScalar multiplier.
Returns
A reference to this Vector after the scalar multiplication.
Note
This operation is available only for ValueType combinations for which multiplication by scalar is well-defined. Types with ambiguous multiplication semantics, such as vec3, are excluded. See https://eel.is/c++draft/expr.prim.req for information on C++ requires-expressions.

◆ operator*=() [2/2]

template<typename ValueType>
Vector< ValueType > & NeoN::Vector< ValueType >::operator*= ( const Vector< ValueType > & rhs)

Multiplies this Vector element-wise by another Vector.

Parameters
rhsVector to multiply with this Vector.
Returns
A reference to this Vector after the element-wise multiplication.
Note
This operation is available only for ValueType combinations for which element-wise multiplication is well-defined. Types with ambiguous multiplication semantics, such as vec3, are excluded. See https://eel.is/c++draft/expr.prim.req for information on C++ requires-expressions.

◆ operator+=()

template<typename ValueType>
Vector< ValueType > & NeoN::Vector< ValueType >::operator+= ( const Vector< ValueType > & rhs)

Adds another Vector element-wise.

Parameters
rhsVector to add to this Vector.
Returns
This Vector after the element-wise addition.

◆ operator-=()

template<typename ValueType>
Vector< ValueType > & NeoN::Vector< ValueType >::operator-= ( const Vector< ValueType > & rhs)

Subtracts another Vector element-wise.

Parameters
rhsVector to subtract from this Vector.
Returns
A reference to this Vector after the element-wise subtraction.

◆ operator=() [1/3]

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

Assigns a value to every element of the Vector.

Parameters
rhsValue assigned to each element.

◆ operator=() [2/3]

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

Assigns the contents of another Vector.

Parameters
rhsVector to copy from.
Warning
The size of this Vector is adjusted to match rhs if necessary.

◆ operator=() [3/3]

template<typename ValueType>
Vector< ValueType > & NeoN::Vector< ValueType >::operator= ( Vector< ValueType > && rhs)
noexcept

Move-assignment operator — transfers ownership of the data buffer.

Swaps the data pointer and size from rhs in O(1) without launching any GPU kernel. The old buffer owned by *this is freed first (after a fence if on GPU). After the move, rhs is left in an empty (size=0, data=nullptr) state. The executor is unchanged — exec_ is const and cannot be moved.

Warning
Invalidates any existing View objects that point into *this.
Parameters
rhsVector whose resources are transferred to this Vector.
Returns
A reference to this Vector.

◆ operator[]() [1/2]

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

◆ operator[]() [2/2]

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

Host-side element access is intentionally disabled.

Vector data may reside in executor-specific memory, such as GPU memory. Direct host-side element access could therefore result in invalid memory access.

Note
Use view() or an executor-aware operation to access the data.

◆ range()

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

Returns the index range of the Vector.

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

Definition at line 418 of file vector.hpp.

◆ resize()

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

Resizes the Vector.

Parameters
sizeNew number of elements.

◆ size()

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

Returns the number of elements in the Vector.

Returns
Number of elements.

Definition at line 332 of file vector.hpp.

◆ ssize()

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

Returns the number of elements as a label.

Returns
Number of elements converted to label.

Definition at line 339 of file vector.hpp.

◆ view() [1/8]

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

Returns a non-owning view of the Vector data.

Returns
View of the Vector data.

Definition at line 363 of file vector.hpp.

◆ view() [2/8]

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

Prevents creating a View from a temporary Vector.

A View does not own the referenced data. Allowing a View to be created from a temporary Vector could therefore result in a dangling view.

◆ view() [3/8]

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

Returns a read-only, non-owning view of the Vector data.

Returns
Read-only view of the Vector data.

Definition at line 370 of file vector.hpp.

◆ view() [4/8]

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

◆ view() [5/8]

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

Returns a non-owning view of a range of the Vector.

Parameters
rangeHalf-open index range [first, last).
Returns
View of the specified range.

Definition at line 391 of file vector.hpp.

◆ view() [6/8]

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

Prevents creating a view of a temporary Vector.

A View does not own the referenced data, so a view of a temporary Vector could become dangling.

◆ view() [7/8]

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

Returns a read-only, non-owning view of a range of the Vector.

Parameters
rangeHalf-open index range [first, last).
Returns
Read-only view of the specified range.

Definition at line 405 of file vector.hpp.

◆ view() [8/8]

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

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