Generation
range
range
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 numbers0, ..., N-1
of typeT
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 numbers0, ..., N-1
. The data type used for the indices is given by the first template argument, which issize_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
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 vectorV
.Example
vec<int, 3> a = {1, 2, 3}; vec<int, 3> b = fill_like(a, 42); // returns [42, 42, 42]
zeros
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
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]