E.V.E
v2023.02.15
 
Loading...
Searching...
No Matches

◆ iota

eve::iota = functor<iota_t>
inlineconstexpr
See also
eve::views::iota if you want a view.

Defined in Header

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
template < eve::conditional_expr C
, eve::arithmetic_simd_value T
>
}
Specifies that a type is a Conditional Expression.
Definition conditional.hpp:28
constexpr auto iota
all numbers from 0 to size() - 1. equivalent to T{ [](int i, int) {return i; } }
Definition iota.hpp:69
typename decltype(detail::as_translated_type(as< T >{}))::type translate_t
Returns the final translated type of T.
Definition translation.hpp:107
EVE Main Namespace.
Definition abi.hpp:19

Parameters

  • tgt : Type wrapper - type of the resulting
  • cond : (optional) - a way to replace undesired elements If no alternative is provided - returns eve::zero(tgt) for disabled elements.

Return value

  • T{0, 1, ...}

Example

#include <eve/module/core.hpp>
#include <tts/tts.hpp>
using n = eve::fixed<4>;
template<typename T>
concept iota_supports = std::invocable<decltype(eve::iota), eve::as<T>>;
// See below - maybe this is what you are looking for?
int main()
{
// basic ints
{
i32s expected {0, 1, 2, 3};
}
// floats
{
f64s expected {0.0, 1.0, 2.0, 3.0};
}
// doesn't work for
{
}
// conditional
{
auto tgt = eve::as<i32s> {};
const auto actual1 = eve::iota[eve::ignore_last(2).else_(5)](tgt);
TTS_EXPECT(eve::all(actual0 == i32s {0, 1, 0, 0}));
TTS_EXPECT(eve::all(actual1 == i32s {0, 1, 5, 5}));
const auto m = eve::logical<i32s> {true, true, false, false};
const auto actual2 = eve::iota[m](tgt);
const auto actual3 = eve::iota[eve::if_(m).else_(5)](tgt);
TTS_EXPECT(eve::all(actual2 == i32s {0, 1, 0, 0}));
TTS_EXPECT(eve::all(actual3 == i32s {0, 1, 5, 5}));
}
}
#include <eve/module/algo.hpp>
void
{
// There is a good chance you found this doc because
// you wanted to enumerate all elements in a sequence.
// It is harder then you might think in a general case.
// If you need to do it for small types (such as vector of chars or shorts)
// look at `eve::algo::for_each_iteration_fixed_overflow`.
// There is no docs for that at this point, because it is very clumsy.
// If you don't care about overflow, just zip with iota view.
// Example: for (int i = 0; auto& x : v) x = (i++) * 2;
{
std::vector<int> v;
v.resize(10);
eve::algo::transform_to(
eve::views::iota(0), v, [](eve::like<int> auto idx) { return idx + idx; });
TTS_EQUAL(v, std::vector<int>({0, 2, 4, 6, 8, 10, 12, 14, 16, 18}));
}
// Example: imperfect for (int i = 0; auto& x : v) x = x << i;
{
std::vector<int> v(5u, 1);
// Here, because we pass v twice, it will not be as perfect as it can but
// it has advantage of being very simple.
eve::algo::transform_to(eve::views::zip(v, eve::views::iota(0)),
v,
[](auto input_idx)
{
auto [input, idx] = input_idx;
return input << idx;
});
TTS_EQUAL(v, std::vector<int>({1, 2, 4, 8, 16}));
}
// Example: handwriting for (int i = 0; auto& x : v) x = x << i;
{
std::vector<int> v(5u, 1);
eve::algo::for_each(eve::views::zip(v, eve::views::iota(0)),
[](eve::algo::iterator auto it, eve::relative_conditional_expr auto ignore)
{
auto [elements_it, index_it] = it;
});
TTS_EQUAL(v, std::vector<int>({1, 2, 4, 8, 16}));
}
}
Specifies semantic compatibility between wrapper/wrapped types.
Definition product_type.hpp:107
Specifies that a type is a Conditional Expression using relative mask.
Definition conditional.hpp:52
constexpr auto all
Computes a bool value which is true if and only if every elements of x evaluates to true.
Definition all.hpp:95
constexpr auto store
Store the elements of a SIMD value into the given memory location.
Definition store.hpp:78
constexpr auto load
Loads data from a pointer or a pair of iterators into a SIMD value.
Definition load.hpp:71
auto else_(V const &v) const
Extends a conditional expression with an alternative value.
Definition conditional.hpp:114
Extensible wrapper for SIMD conditional.
Definition conditional.hpp:102
constexpr auto else_(V const &v) const
Extends a conditional expression with an alternative value.
Definition conditional.hpp:342
Conditional expression ignoring the k last lanes from a eve::simd_value.
Definition conditional.hpp:320