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 for vector<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.

inline T *data()

Returns a pointer to the underlying storage data.

inline const T *data() const

Returns a pointer to the underlying storage data.

inline T &at(size_t i)

Returns a reference to the item at index i.

inline const T &at(size_t i) const

Returns a constant reference to the item at index i.

inline T &operator[](size_t i)

Returns a reference to the item at index i.

inline const T &operator[](size_t i) const

Returns a constant reference to the item at index i.

inline T *begin()

Returns a pointer to the first element.

inline const T *begin() const

Returns a pointer to the first element.

inline const T *cbegin() const

Returns a pointer to the first element.

inline T *end()

Returns a pointer to one past the last element.

inline const T *end() const

Returns a pointer to one past the last element.

inline const T *cend() const

Returns a pointer to one past the last element.

inline T get(size_t x) const

Copy the element at index i.

inline void set(size_t x, T value)

Set the element at index i.

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 a vec<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.

Aliases

template<typename T>
using kernel_float::scalar = vector<T, extent<1>>
template<typename T, size_t N>
using kernel_float::vec = vector<T, extent<N>>
template<typename T>
using kernel_float::vec2 = vec<T, 2>
template<typename T>
using kernel_float::vec3 = vec<T, 3>
template<typename T>
using kernel_float::vec4 = vec<T, 4>
template<typename T>
using kernel_float::vec5 = vec<T, 5>
template<typename T>
using kernel_float::vec6 = vec<T, 6>
template<typename T>
using kernel_float::vec7 = vec<T, 7>
template<typename T>
using kernel_float::vec8 = vec<T, 8>