1 #ifndef COTILA_VECTOR_UTILITY_H_ 2 #define COTILA_VECTOR_UTILITY_H_ 22 typename F,
typename T,
typename... Vectors,
23 typename U = std::invoke_result_t<F, T,
typename Vectors::value_type...>,
25 detail::all_same_value<std::size_t, Vectors::size...>::value>
27 const Vectors &... vectors) {
29 for (std::size_t i = 0; i < N; ++i)
30 op_applied[i] = std::apply(f, std::forward_as_tuple(v[i], vectors[i]...));
42 template <
typename T, std::
size_t N,
typename F,
typename U>
45 for (std::size_t i = 0; i < vector<T, N>::size; ++i)
46 r = std::apply(std::forward<F>(f), std::forward_as_tuple(r, v[i]));
56 template <
typename T,
typename U, std::
size_t N>
58 return elementwise([](
const U u) {
return static_cast<T
>(u); }, v);
67 template <std::
size_t N,
typename T>
84 template <std::
size_t N,
typename T>
86 return ((max - min) / (N - 1)) * iota<N, T>() + min;
97 for (
auto &x : filled)
108 template <std::
size_t N,
typename F> constexpr decltype(
auto)
generate(F &&f) {
120 template <std::
size_t N,
typename T>
126 for (std::size_t i = 0; i < N; ++i)
127 rotated[i] = v[(i + n) % N];
139 template <std::
size_t M,
typename T, std::
size_t N>
143 for (std::size_t i = 0; i < M; ++i)
144 sliced[i] = v[i + start];
157 template <
typename T, std::
size_t N, std::
size_t M>
160 for (std::size_t i = 0; i < N; ++i)
162 for (std::size_t i = 0; i < M; ++i)
163 concatted[i + N] = b[i];
171 #endif // COTILA_VECTOR_UTILITY_H_ constexpr vector< T, N > rotate(vector< T, N > v, int n)
shifts vector elements
Definition: utility.h:121
constexpr vector< U, N > elementwise(F f, const vector< T, N > &v, const Vectors &... vectors)
applies a function elementwise between many vectors
Definition: utility.h:26
constexpr vector< T, N > linspace(T min, T max)
generates a vector of equally spaced elements
Definition: utility.h:85
constexpr U accumulate(const vector< T, N > &v, U init, F &&f)
accumulates an operation across a vector
Definition: utility.h:43
constexpr vector< T, M > slice(vector< T, N > v, std::size_t start=0)
slices a vector into a subvector
Definition: utility.h:140
constexpr T max(const vector< T, N > &v)
computes the maximum valued element
Definition: math.h:119
A container representing a vector.
Definition: vector.h:25
constexpr vector< T, N > iota(T value=T())
generates a vector containing consecutive elements
Definition: utility.h:68
constexpr T min(const vector< T, N > &v)
computes the minimum valued element
Definition: math.h:109
constexpr vector< T, N+M > concat(vector< T, N > a, vector< T, M > b)
concatenates two vectors
Definition: utility.h:158
Contains the definition of the cotila::vector class.
constexpr vector< T, N > cast(const vector< U, N > &v)
casts a vector to another type
Definition: utility.h:57
constexpr vector< T, N > fill(T value)
generates a vector containing a single value
Definition: utility.h:95
decltype(auto) constexpr generate(F &&f)
generates a vector as a function of its index
Definition: utility.h:108