38template<
typename ValueType>
121 template<
typename func>
224 requires requires(ValueType a, ValueType b) { a* b; };
239 requires requires(ValueType a,
scalar b) { a* b; };
254 requires requires(ValueType a, ValueType b) { a *= b; };
269 requires requires(ValueType a,
scalar b) { a *= b; };
283 [[nodiscard]] ValueType*
data() {
return data_; }
290 [[nodiscard]]
const ValueType*
data()
const {
return data_; }
297 [[nodiscard]] ValueType*
begin() {
return data_; }
304 [[nodiscard]]
const ValueType*
begin()
const {
return data_; }
311 [[nodiscard]] ValueType*
end() {
return data_ +
size(); }
318 [[nodiscard]]
const ValueType*
end()
const {
return data_ +
size(); }
346 [[nodiscard]]
bool empty()
const {
return size() == 0; }
418 [[nodiscard]]
inline std::pair<localIdx, localIdx>
range()
const
426 ValueType* data_ {
nullptr};
443template<
typename ValueType>
453template<
typename ValueType>
Reference executor for serial CPU execution.
An executor-aware contiguous container for numerical data with vector-style arithmetic semantics.
Vector(const Executor &exec, sizeType size)
Creates an uninitialized Vector with the given size on an executor.
Vector(Vector< ValueType > &&rhs) noexcept
Move constructor.
ValueType & operator[](const localIdx i)=delete
Host-side element access is intentionally disabled.
Vector(const Vector< ValueType > &rhs)
Copy constructor.
const ValueType * begin() const
Returns a const pointer to the first element of the Vector.
Vector< ValueType > copyToExecutor(Executor dstExec) const
Creates a copy of the Vector on the specified executor.
Vector< ValueType > operator*(const Vector< ValueType > &rhs)
Multiplies two Vectors element-wise.
const ValueType * end() const
Returns a const pointer one past the last element of the Vector.
Vector(const Executor &exec, const Vector< ValueType > &in)
Creates a copy of another Vector on the specified executor.
View< ValueType > view(std::pair< localIdx, localIdx > range) &
Returns a non-owning view of a range of the Vector.
ValueType * data()
Returns a pointer to the underlying Vector data.
Vector< ValueType > & operator=(Vector< ValueType > &&rhs) noexcept
Move-assignment operator — transfers ownership of the data buffer.
std::pair< localIdx, localIdx > range() const
View< const ValueType > view(std::pair< localIdx, localIdx > range) const &&=delete
label ssize() const
Returns the number of elements as a label.
void operator=(const ValueType &rhs)
Assigns a value to every element of the Vector.
View< const ValueType > view() const &
Returns a read-only, non-owning view of the Vector data.
Vector< ValueType > & operator*=(const scalar rhs)
Multiplies every element of the Vector by a scalar.
Vector(const Executor &exec, sizeType size, ValueType value)
Creates a Vector with the given size and initializes all elements to a value.
View< const ValueType > view(std::pair< localIdx, localIdx > range) const &
Returns a read-only, non-owning view of a range of the Vector.
const ValueType * data() const
Returns a pointer to the underlying Vector data.
Vector< ValueType > & operator*=(const Vector< ValueType > &rhs)
Multiplies this Vector element-wise by another Vector.
bool empty() const
Checks whether the Vector contains no elements.
void apply(func f)
Applies a function to the elements of the Vector.
void resize(const sizeType size)
Resizes the Vector.
Vector< ValueType > operator*(const scalar rhs)
Multiplies every element of the Vector by a scalar.
const Executor & exec() const
Vector< ValueType > & operator+=(const Vector< ValueType > &rhs)
Adds another Vector element-wise.
~Vector()
Destroys the Vector object.
View< ValueType > view(std::pair< localIdx, localIdx > range) &&=delete
Prevents creating a view of a temporary Vector.
ValueType * end()
Returns a pointer one past the last element of the Vector.
ValueType VectorValueType
Vector(const Executor &exec, std::vector< ValueType > in)
Creates a Vector from a std::vector on the given executor.
void copyToHost(Vector< ValueType > &result)
Copies the Vector data to a host-resident Vector.
View< ValueType > view() &&=delete
Prevents creating a View from a temporary Vector.
Vector< ValueType > copyToHost() const
Creates a host-resident copy of the Vector.
Vector< ValueType > & operator-=(const Vector< ValueType > &rhs)
Subtracts another Vector element-wise.
const ValueType & operator[](const localIdx i) const =delete
void operator=(const Vector< ValueType > &rhs)
Assigns the contents of another Vector.
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.
ValueType * begin()
Returns a pointer to the first element of the Vector.
View< const ValueType > view() const &&=delete
Integer types used throughout NeoN.
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
localIdx toLocalIdx(sizeType value)
Vector< ValueType > operator-(Vector< ValueType > lhs, const Vector< ValueType > &rhs)
Subtracts two Vectors element-wise.
void map(ContType< ValueType > &cont, const Inner inner, std::pair< localIdx, localIdx > range={0, 0})
Map a field using a specific executor.
Vector< ValueType > operator+(Vector< ValueType > lhs, const Vector< ValueType > &rhs)
Adds two Vectors element-wise.
void validateRange(std::pair< localIdx, localIdx > range, sizeType size)