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_coefficient{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_static_vector_space_descriptors<
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_static_vector_space_descriptors<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);
69 return detail::average_reduce_impl(std::forward<Arg>(arg), std::index_sequence<index, indices...>{}, std::make_index_sequence<index_count_v<Arg>>{});
80 template<
internal::has_uniform_static_vector_space_descriptors Arg>
82 template<
typename Arg, std::enable_if_t<
internal::has_uniform_static_vector_space_descriptors<Arg>,
int> = 0>
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>>{},
101 internal::largest_vector_space_descriptor<scalar_type_of_t<Arg>>(get_vector_space_descriptor<0>(arg), get_vector_space_descriptor<1>(arg))};
109 std::size_t denom = 1;
124 #endif //OPENKALMAN_AVERAGE_REDUCE_HPP constexpr auto count_indices(const T &t)
Get the number of indices available to address the components of an indexible object.
Definition: count_indices.hpp:33
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
An operation involving some number of values.
Definition: operation.hpp:69
typename scalar_type_of< T >::type scalar_type_of_t
helper template for scalar_type_of.
Definition: scalar_type_of.hpp:54
constexpr bool indexible
T is a generalized tensor type.
Definition: indexible.hpp:32
Definition: tuple_reverse.hpp:103
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
The constant associated with T, assuming T is a constant_matrix.
Definition: constant_coefficient.hpp:36
decltype(auto) constexpr all_vector_space_descriptors(const T &t)
Return a collection of coordinates::pattern objects associated with T.
Definition: all_vector_space_descriptors.hpp:52
The root namespace for OpenKalman.
Definition: basics.hpp:34
The constant associated with T, assuming T is a constant_diagonal_matrix.
Definition: constant_diagonal_coefficient.hpp:32
constexpr std::size_t dynamic_size
A constant indicating that a size or index is dynamic.
Definition: global-definitions.hpp:33
constant_coefficient(const T &) -> constant_coefficient< T >
Deduction guide for constant_coefficient.
constexpr auto get_index_dimension_of(const T &t, N n=N{})
Get the runtime dimensions of index N of indexible T.
Definition: get_index_dimension_of.hpp:34
constexpr bool index
An object describing a collection of /ref values::index objects.
Definition: index.hpp:75