Types
vector
-
template<typename T, typename E, class S>
struct vector : public S Container that store fixed number of elements of type
T
.It is not recommended to use this class directly, instead, use the type
vec<T, N>
which is an alias forvector<T, extent<N>, vector_storage<T, E>>
.- Template Parameters:
T – The type of the values stored within the vector.
E – The size of this vector. Should be of type
extent<N>
.S – The object’s storage class. Should be the type
vector_storage<T, E>
Public Functions
-
inline storage_type &storage()
Returns a reference to the underlying storage type.
-
inline const storage_type &storage() const
Returns a reference to the underlying storage type.
-
template<typename ...Is>
inline select_type<self_type, Is...> select(const Is&... indices) Selects elements from the this vector based on the specified indices.
Example
vec<float, 6> input = {0, 10, 20, 30, 40, 50}; vec<float, 4> vec1 = select(input, 0, 4, 4, 2); // [0, 40, 40, 20] vec<int, 4> indices = {0, 4, 4, 2}; vec<float, 4> vec2 = select(input, indices); // [0, 40, 40, 20]
-
template<typename R, RoundingMode Mode = RoundingMode::ANY>
inline vector<R, extent_type> cast() const Cast the elements of this vector to type
R
and returns a new vector.
-
template<size_t... Ns>
inline vector<T, extent<Ns...>> broadcast(extent<Ns...> new_size = {}) const Broadcast this vector into a new size
(Ns...)
.
-
template<typename F>
inline vector<result_t<F, T>, E> map(F fun) const Apply the given function
F
to each element of this vector and returns a new vector with the results.
-
template<typename F>
inline T reduce(F fun) const Reduce the elements of the given vector input into a single value using the function
F
.This function should be a binary function that takes two elements and returns one element. The order in which the elements are reduced is not specified and depends on the reduction function and the vector type.
-
inline flatten_type<vector> flatten() const
Flattens the elements of this vector. For example, this turns a
vec<vec<int, 2>, 3>
into avec<int, 6>
.
-
template<typename F>
inline void for_each(F fun) const Apply the given function
F
to each element of this vector.
-
template<typename L, typename R, typename T2 = promote_t<T, vector_value_type<L>, vector_value_type<R>>, typename E2 = broadcast_extent<E, vector_extent_type<L>, vector_extent_type<R>>>
inline vector<T2, E2> fma(const L &lhs, const R &rhs) const Returns the result of
*this + lhs * rhs
.The operation is performed using a single
kernel_float::fma
call, which may be faster then perform the addition and multiplication separately.
Public Static Functions
-
static inline constexpr size_t size()
Returns the number of elements in this vector.