util¶
sequence_utils¶
Utility functions and type traits for compile-time sequence operations.
This file provides a set of template metaprogramming utilities for working with std::index_sequence and similar compile-time sequences. It includes type traits, sequence manipulations, and arithmetic operations on sequences.
-
namespace squint
Typedefs
-
template<typename Sequence1, typename Sequence2>
using concat_sequence_t = typename concat_sequence<Sequence1, Sequence2>::type¶
-
template<typename Sequence>
using init_sequence_t = typename init_sequence<Sequence>::type¶
-
template<typename Sequence, std::size_t New>
using prepend_sequence_t = typename prepend_sequence<Sequence, New>::type¶
-
template<typename Sequence, std::size_t New>
using append_sequence_t = typename append_sequence<Sequence, New>::type¶
-
template<typename Sequence, std::size_t N>
using remove_last_n_t = typename remove_last_n<Sequence, N>::type¶
-
template<typename Sequence>
using reverse_sequence_t = typename reverse_sequence<Sequence>::type¶
-
template<std::size_t N, std::size_t Value>
using repeat_sequence_t = typename repeat_sequence<N, Value>::type¶
-
template<typename Sequence, typename IndexPermutation, std::size_t pad_value>
using apply_permutation_t = typename apply_permutation<Sequence, IndexPermutation, pad_value>::type¶
-
template<typename Sequence1, typename Sequence2>
using multiply_sequences_t = typename multiply_sequences<Sequence1, Sequence2>::type¶
-
template<typename Sequence, template<std::size_t> class Pred>
using filter_sequence_t = typename filter_sequence<Sequence, Pred>::type¶
-
template<typename Sequence, typename IndexSequence>
using select_values_t = typename select_values<Sequence, IndexSequence>::type¶
Functions
-
template<std::size_t... Ix>
constexpr auto make_array(std::index_sequence<Ix...>)¶ Creates an array from an index sequence.
- Template Parameters:
Ix – Variadic template parameter for indices.
- Returns:
std::array<std::size_t, sizeof…(Ix)> An array containing the indices.
-
template<std::size_t... Ix>
constexpr auto product(std::index_sequence<Ix...>)¶ Computes the product of elements in an index sequence.
- Template Parameters:
Ix – Variadic template parameter for indices.
- Returns:
std::size_t The product of all indices in the sequence.
-
template<std::size_t... Ix>
constexpr auto sum(std::index_sequence<Ix...>)¶ Computes the sum of elements in an index sequence.
- Template Parameters:
Ix – Variadic template parameter for indices.
- Returns:
std::size_t The sum of all indices in the sequence.
-
template<std::size_t... Ix>
constexpr auto max(std::index_sequence<Ix...>) -> std::size_t¶ Finds the maximum value in an index sequence.
- Template Parameters:
Ix – Variadic template parameter for indices.
- Returns:
std::size_t The maximum value in the sequence.
-
template<std::size_t... Ix>
constexpr auto all_equal(std::index_sequence<Ix...>) -> bool¶ Checks if all elements of an index sequence are equal.
- Template Parameters:
Ix – Variadic template parameter for indices.
- Returns:
bool True if all elements are equal, false otherwise.
-
template<std::size_t... Ix>
constexpr auto all_less_than(std::index_sequence<Ix...>, std::size_t max_value) -> bool¶ Checks if all elements of an index sequence are less than a given value.
- Template Parameters:
Ix – Variadic template parameter for indices.
- Parameters:
max_value – The maximum value to compare against.
- Returns:
bool True if all elements are less than max_value, false otherwise.
-
template<typename Sequence>
constexpr auto is_unique() -> bool¶ Checks if a sequence has no duplicates.
Variables
-
template<typename Sequence1, typename Sequence2>
constexpr bool implicit_convertible_shapes_v = implicit_convertible_shapes<Sequence1, Sequence2>::value¶
-
template<typename Sequence1, typename Sequence2>
constexpr bool implicit_convertible_strides_v = implicit_convertible_strides<Sequence1, Sequence2>::value¶
-
template<std::size_t... Rest, std::size_t New>
struct append_sequence<std::index_sequence<Rest...>, New>¶ - #include <squint/util/sequence_utils.hpp>
-
template<typename Sequence, typename IndexPermutation, std::size_t pad_value>
struct apply_permutation¶ - #include <squint/util/sequence_utils.hpp>
Apply index permutation to a sequence.
Public Types
-
using type = decltype(helper<concat_sequence_t<Sequence, repeat_sequence_t<IndexPermutation::size() - Sequence::size(), pad_value>>>(IndexPermutation{}))¶
Public Static Functions
-
template<typename S, std::size_t... Ns>
static auto helper(std::index_sequence<Ns...>) -> std::index_sequence<std::get<Ns>(make_array(S{}))...>¶
-
using type = decltype(helper<concat_sequence_t<Sequence, repeat_sequence_t<IndexPermutation::size() - Sequence::size(), pad_value>>>(IndexPermutation{}))¶
-
template<std::size_t... Ns1, std::size_t... Ns2>
struct concat_sequence<std::index_sequence<Ns1...>, std::index_sequence<Ns2...>>¶ - #include <squint/util/sequence_utils.hpp>
-
template<typename Sequence, template<std::size_t> class Pred>
struct filter_sequence¶ - #include <squint/util/sequence_utils.hpp>
Helper to filter a sequence based on a predicate.
-
template<typename Sequence1, typename Sequence2>
struct implicit_convertible_shapes¶ - #include <squint/util/sequence_utils.hpp>
Helper to determine if two sequences representing tensor shapes can be implicitly converted.
Public Static Functions
-
static inline constexpr auto helper() -> bool¶
-
static inline constexpr auto helper() -> bool¶
-
template<typename Sequence1, typename Sequence2>
struct implicit_convertible_strides¶ - #include <squint/util/sequence_utils.hpp>
Helper to determine if two sequences representing tensor strides can be implicitly converted.
Public Static Functions
-
static inline constexpr auto helper() -> bool¶
-
static inline constexpr auto helper() -> bool¶
-
template<typename Sequence>
struct init_sequence¶ - #include <squint/util/sequence_utils.hpp>
Helper to remove the last element from a sequence.
Public Types
Public Static Functions
-
template<typename S, std::size_t... Ns>
static auto helper(std::index_sequence<Ns...>) -> std::index_sequence<std::get<Ns>(make_array(S{}))...>¶
-
template<typename S, std::size_t... Ns>
-
template<typename T>
struct is_index_sequence : public std::false_type¶ - #include <squint/util/sequence_utils.hpp>
Type trait to check if a type is an index sequence.
- Template Parameters:
T – The type to check.
-
template<std::size_t... Dims>
struct is_index_sequence<std::index_sequence<Dims...>> : public std::true_type¶ - #include <squint/util/sequence_utils.hpp>
-
template<std::size_t... Ns1, std::size_t... Ns2>
struct multiply_sequences<std::index_sequence<Ns1...>, std::index_sequence<Ns2...>>¶ - #include <squint/util/sequence_utils.hpp>
-
template<std::size_t... Rest, std::size_t New>
struct prepend_sequence<std::index_sequence<Rest...>, New>¶ - #include <squint/util/sequence_utils.hpp>
-
template<typename Sequence, std::size_t N>
struct remove_last_n¶ - #include <squint/util/sequence_utils.hpp>
Helper to remove the last N elements from a sequence.
Public Types
Public Static Functions
-
template<typename S, std::size_t... Ns>
static auto helper(std::index_sequence<Ns...>) -> std::index_sequence<std::get<Ns>(make_array(S{}))...>¶
-
template<typename S, std::size_t... Ns>
-
template<std::size_t N, std::size_t Value>
struct repeat_sequence¶ - #include <squint/util/sequence_utils.hpp>
Helper to make repeating index sequences of a single value and length N.
-
template<typename Sequence>
struct reverse_sequence¶ - #include <squint/util/sequence_utils.hpp>
Helper to reverse an index sequence.
-
template<typename Sequence, typename IndexSequence>
struct select_values¶ - #include <squint/util/sequence_utils.hpp>
Helper to select values from a sequence using another sequence of indices.
Public Types
-
using type = decltype(helper(IndexSequence{}))¶
-
using type = decltype(helper(IndexSequence{}))¶
-
template<typename Sequence1, typename Sequence2>
math_utils¶
Mathematical utility functions for the Squint library.
This file provides mathematical utility functions, including an implementation of approximate equality for floating-point types.
-
namespace squint
Functions
-
template<typename T>
auto approx_equal(T a, T b, T epsilon = DEFAULT_EPSILON, T abs_th = std::numeric_limits<T>::epsilon()) -> bool¶ Checks if two arithmetic values are approximately equal.
This function compares two values for approximate equality, taking into account both relative and absolute tolerances.
Note
This function requires that T satisfies the arithmetic concept.
- Template Parameters:
T – The arithmetic type of the values being compared.
- Parameters:
a – The first value to compare.
b – The second value to compare.
epsilon – The relative tolerance for the comparison (default: DEFAULT_EPSILON).
abs_th – The absolute tolerance for the comparison (default: std::numeric_limits<T>::epsilon()).
- Returns:
bool True if the values are approximately equal, false otherwise.
Variables
-
constexpr long double DEFAULT_EPSILON = 128 * 1.192092896e-04¶
Default epsilon value for floating-point comparisons.
This value is used as the default tolerance in approximate equality comparisons.
-
template<typename T>