Generation

range

template<typename T, size_t N>
inline vector<T, extent<N>> kernel_float::range()

Generate vector consisting of the numbers 0, ..., N-1 of type T

Example

// Returns [0, 1, 2]
vec<float, 3> vec = range<float, 3>();

range

template<size_t N, typename F, typename T = result_t<F, size_t>>
inline vector<T, extent<N>> kernel_float::range(F fun)

Generate vector consisting of the result fun(0), ..., fun(N-1)

Example

// Returns [0.0f, 2.0f, 4.0f]
vec<float, 3> vec = range<3>([](auto i){ return float(i * 2.0f); });

range_like

template<typename V>
inline into_vector_type<V> kernel_float::range_like(const V& = {})

Takes a vector vec<T, N> and returns a new vector consisting of the numbers 0, ..., N-1 of type T

Example

auto input = vec<float, 3>(5.0f, 10.0f, -1.0f);
auto indices = range_like(input);  // returns [0.0f, 1.0f, 2.0f]

each_index

template<typename T = size_t, typename V>
inline vector<T, vector_extent_type<V>> kernel_float::each_index(const V& = {})

Takes a vector of size N and returns a new vector consisting of the numbers 0, ..., N-1. The data type used for the indices is given by the first template argument, which is size_t by default. This function is useful when needing to iterate over the indices of a vector.

Example

// Returns [0, 1, 2] of type size_t
vec<size_t, 3> a = each_index(float3(6, 4, 2));

// Returns [0, 1, 2] of type int.
vec<int, 3> b = each_index<int>(float3(6, 4, 2));

vec<float, 3> input = {1.0f, 2.0f, 3.0f, 4.0f};
for (auto index: each_index<int>(input)) {
  printf("%d] %f\n", index, input[index]);
}

fill

template<size_t N, typename T>
inline vector<T, extent<N>> kernel_float::fill(T value = {}, extent<N> = {})

Returns a vector containing N copies of value.

Example

vec<int, 3> a = fill<3>(42); // returns [42, 42, 42]

fill_like

template<typename V, typename T = vector_value_type<V>, typename E = vector_extent_type<V>>
inline vector<T, E> kernel_float::fill_like(const V&, T value)

Returns a vector filled with value having the same type and size as input vector V.

Example

vec<int, 3> a = {1, 2, 3};
vec<int, 3> b = fill_like(a, 42); // returns [42, 42, 42]

zeros

template<typename T, size_t N>
inline vector<T, extent<N>> kernel_float::zeros(extent<N> = {})

Returns a vector containing N copies of T(0).

Example

vec<int, 3> a = zeros<int, 3>(); // returns [0, 0, 0]

zeros_like

template<typename V, typename T = vector_value_type<V>, typename E = vector_extent_type<V>>
inline vector<T, E> kernel_float::zeros_like(const V& = {})

Returns a vector filled with zeros having the same type and size as input vector V.

Example

vec<int, 3> a = {1, 2, 3};
vec<int, 3> b = zeros_like(a); // returns [0, 0, 0]

ones

template<typename T, size_t N>
inline vector<T, extent<N>> kernel_float::ones(extent<N> = {})

Returns a vector containing N copies of T(1).

Example

vec<int, 3> a = ones<int, 3>(); // returns [1, 1, 1]

ones_like

template<typename V, typename T = vector_value_type<V>, typename E = vector_extent_type<V>>
inline vector<T, E> kernel_float::ones_like(const V& = {})

Returns a vector filled with ones having the same type and size as input vector V.

Example

vec<int, 3> a = {1, 2, 3};
vec<int, 3> b = ones_like(a); // returns [1, 1, 1]