16 #ifndef OPENKALMAN_AVERAGE_REDUCE_HPP 17 #define OPENKALMAN_AVERAGE_REDUCE_HPP 23 template<
typename Arg, std::size_t...indices, std::size_t...Ix>
24 constexpr decltype(
auto)
25 average_reduce_impl(Arg&& arg,
std::index_sequence<indices...> indices_seq,
std::index_sequence<Ix...> seq)
27 if constexpr (constant_matrix<Arg>)
29 return make_constant<Arg>(
constant_value{arg}, internal::get_reduced_vector_space_descriptor<Ix, indices...>(std::forward<Arg>(arg))...);
33 return scalar_quotient(
34 reduce<indices...>(std::plus<scalar_type_of_t<Arg>> {}, std::forward<Arg>(arg)),
35 internal::count_reduced_dimensions(arg, indices_seq, seq));
51 template<std::size_t
index, std::size_t...indices, internal::has_uniform_patterns<
index, indices...> Arg> requires
52 (not empty_object<Arg>)
55 template<std::size_t
index, std::size_t...indices,
typename Arg, std::enable_if_t<
56 internal::has_uniform_patterns<Arg,
index, indices...> and (not empty_object<Arg>),
int> = 0>
57 constexpr decltype(
auto)
61 if constexpr (dimension_size_of_index_is<Arg, index, 1>)
64 if constexpr (
sizeof...(indices) == 0)
return std::forward<Arg>(arg);
80 template<
internal::has_uniform_patterns Arg>
82 template<
typename Arg, std::enable_if_t<
internal::has_uniform_patterns<Arg>,
int> = 0>
84 constexpr scalar_type_of_t<Arg>
87 if constexpr (zero<Arg>)
91 else if constexpr (constant_matrix<Arg>)
95 else if constexpr (constant_diagonal_matrix<Arg>)
99 std::divides<scalar_type_of_t<Arg>>{},
100 constant_diagonal_value{arg},
101 internal::largest_pattern<scalar_type_of_t<Arg>>(get_pattern_collection<0>(arg), get_pattern_collection<1>(arg)));
105 auto r =
reduce(std::plus<scalar_type_of_t<Arg>>{}, std::forward<Arg>(arg));
107 if constexpr (index_count_v<Arg> == stdex::dynamic_extent)
109 std::size_t denom = 1;
110 for (std::size_t i = 0; i <
count_indices(arg); ++i) denom *= get_index_dimension_of(arg, i);
115 auto denom = (
std::apply([](
const auto&...d){
return (
get_dimension(d) * ...); }, all_vector_space_descriptors(arg)));
decltype(auto) constexpr average_reduce(Arg &&arg)
Perform a partial reduction by taking the average along one or more indices.
Definition: average_reduce.hpp:59
constexpr auto count_indices(const T &)
Get the number of indices necessary to address all the components of an indexible object...
Definition: count_indices.hpp:51
constexpr bool indexible
T is a multidimensional array type.
Definition: indexible.hpp:32
decltype(auto) constexpr reduce(BinaryFunction &&b, Arg &&arg)
Perform a partial reduction based on an associative binary function, across one or more indices...
Definition: reduce.hpp:143
decltype(auto) constexpr apply(F &&f, T &&t)
A generalization of std::apply.
Definition: apply.hpp:49
constexpr auto get_dimension(const Arg &arg)
Get the vector dimension of coordinates::pattern Arg.
Definition: get_dimension.hpp:54
The root namespace for OpenKalman.
Definition: basics.hpp:34
constexpr auto constant_value(T &&t)
The constant value associated with a constant_object or constant_diagonal_object. ...
Definition: constant_value.hpp:37
Definition: trait_backports.hpp:64
constexpr auto operation(Operation &&op, Args &&...args)
A potentially constant-evaluated operation involving some number of values.
Definition: operation.hpp:98
constexpr bool index
An object describing a collection of /ref values::index objects.
Definition: index.hpp:77