Skip to content

Commit

Permalink
[filter] simplify deducer by using static operator
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancoisCarouge committed Nov 2, 2024
1 parent c105635 commit 0790408
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 42 deletions.
77 changes: 37 additions & 40 deletions include/fcarouge/internal/factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ namespace fcarouge::internal {
//! convention insensitive?
//! @todo Some of these overload should probably be removed to guide the user
//! towards better initialization practices?
template <typename Filter = void> struct make_filter {
template <typename Filter = void> struct filter_deducer {
template <typename... Arguments>
inline constexpr auto
operator()([[maybe_unused]] Arguments... arguments) const
static inline constexpr auto
operator()([[maybe_unused]] Arguments... arguments)
requires(std::same_as<Filter, void>)
{
static_assert(false,
Expand All @@ -70,21 +70,21 @@ template <typename Filter = void> struct make_filter {
}

//! @todo Rename, clean the concet: undeduced?
inline constexpr auto operator()() const -> x_z_p_r_f<double, double>
static inline constexpr auto operator()() -> x_z_p_r_f<double, double>
requires(std::same_as<Filter, void>);

inline constexpr auto operator()() const { return Filter{}; }
static inline constexpr auto operator()() { return Filter{}; }

template <typename State, typename Output>
inline constexpr auto operator()(state<State> x,
[[maybe_unused]] output_t<Output> z) const {
static inline constexpr auto operator()(state<State> x,
[[maybe_unused]] output_t<Output> z) {
return x_z_p_r_f<State, Output>{x.value};
}

template <typename State, typename Output, typename Input>
inline constexpr auto operator()(state<State> x,
[[maybe_unused]] output_t<Output> z,
[[maybe_unused]] input_t<Input> u) const {
static inline constexpr auto operator()(state<State> x,
[[maybe_unused]] output_t<Output> z,
[[maybe_unused]] input_t<Input> u) {
using kt = x_z_u_p_q_r_us_ps<State, Output, Input, empty_pack, empty_pack>;
return kt{typename kt::state{x.value}};
}
Expand All @@ -98,14 +98,14 @@ template <typename Filter = void> struct make_filter {
requires requires(ProcessUncertainty q) {
requires std::invocable<ProcessUncertainty, State, Ps...>;
}
inline constexpr auto
static inline constexpr auto
operator()(state<State> x, [[maybe_unused]] output_t<Output> z,
[[maybe_unused]] input_t<Input> u,
estimate_uncertainty<EstimateUncertainty> p,
process_uncertainty<ProcessUncertainty> q,
output_uncertainty<OutputUncertainty> r,
state_transition<StateTransition> f, input_control<InputControl> g,
[[maybe_unused]] prediction_types_t<Ps...> pts) const {
[[maybe_unused]] prediction_types_t<Ps...> pts) {
using kt = x_z_u_p_q_r_f_g_ps<State, Output, Input, empty_pack,
repack_t<prediction_types_t<Ps...>>>;
return kt{typename kt::state{x.value},
Expand All @@ -118,11 +118,11 @@ template <typename Filter = void> struct make_filter {

template <typename State, typename Output, typename Input, typename... Us,
typename... Ps>
inline constexpr auto
static inline constexpr auto
operator()(state<State> x, [[maybe_unused]] output_t<Output> z,
[[maybe_unused]] input_t<Input> u,
[[maybe_unused]] update_types_t<Us...> uts,
[[maybe_unused]] prediction_types_t<Ps...> pts) const {
[[maybe_unused]] prediction_types_t<Ps...> pts) {
using kt =
x_z_u_p_q_r_us_ps<State, Output, Input, repack_t<update_types_t<Us...>>,
repack_t<prediction_types_t<Ps...>>>;
Expand All @@ -139,15 +139,15 @@ template <typename Filter = void> struct make_filter {
requires std::invocable<Transition, State, Ps...>;
requires std::invocable<Observation, State, Ps...>;
}
inline constexpr auto
static inline constexpr auto
operator()(state<State> x, [[maybe_unused]] output_t<Output> z,
estimate_uncertainty<EstimateUncertainty> p,
process_uncertainty<ProcessUncertainty> q,
output_uncertainty<OutputUncertainty> r,
output_model<OutputModel> h, transition<Transition> ff,
observation<Observation> hh,
[[maybe_unused]] update_types_t<Us...> uts,
[[maybe_unused]] prediction_types_t<Ps...> pts) const {
[[maybe_unused]] prediction_types_t<Ps...> pts) {
using kt =
x_z_p_q_r_hh_us_ps<State, Output, repack_t<update_types_t<Us...>>,
repack_t<prediction_types_t<Ps...>>>;
Expand All @@ -163,13 +163,12 @@ template <typename Filter = void> struct make_filter {
template <typename State, typename Output, typename EstimateUncertainty,
typename ProcessUncertainty, typename OutputUncertainty,
typename OutputModel, typename StateTransition>
inline constexpr auto operator()(state<State> x,
[[maybe_unused]] output_t<Output> z,
estimate_uncertainty<EstimateUncertainty> p,
process_uncertainty<ProcessUncertainty> q,
output_uncertainty<OutputUncertainty> r,
output_model<OutputModel> h,
state_transition<StateTransition> f) const {
static inline constexpr auto
operator()(state<State> x, [[maybe_unused]] output_t<Output> z,
estimate_uncertainty<EstimateUncertainty> p,
process_uncertainty<ProcessUncertainty> q,
output_uncertainty<OutputUncertainty> r,
output_model<OutputModel> h, state_transition<StateTransition> f) {
using kt = x_z_p_q_r_h_f<State, Output>;
return kt{typename kt::state{x.value},
typename kt::estimate_uncertainty{p.value},
Expand All @@ -181,10 +180,10 @@ template <typename Filter = void> struct make_filter {

template <typename State, typename Output, typename EstimateUncertainty,
typename OutputUncertainty>
inline constexpr auto
static inline constexpr auto
operator()(state<State> x, [[maybe_unused]] output_t<Output> z,
estimate_uncertainty<EstimateUncertainty> p,
output_uncertainty<OutputUncertainty> r) const {
output_uncertainty<OutputUncertainty> r) {
using kt = x_z_p_r_f<State, Output>;
return kt{typename kt::state{x.value},
typename kt::estimate_uncertainty{p.value},
Expand All @@ -193,11 +192,11 @@ template <typename Filter = void> struct make_filter {

template <typename State, typename Output, typename EstimateUncertainty,
typename OutputUncertainty, typename ProcessUncertainty>
inline constexpr auto
static inline constexpr auto
operator()(state<State> x, [[maybe_unused]] output_t<Output> z,
estimate_uncertainty<EstimateUncertainty> p,
process_uncertainty<ProcessUncertainty> q,
output_uncertainty<OutputUncertainty> r) const {
output_uncertainty<OutputUncertainty> r) {
using kt = x_z_p_q_r_h_f<State, Output>;
return kt{typename kt::state{x.value},
typename kt::estimate_uncertainty{p.value},
Expand All @@ -208,12 +207,12 @@ template <typename Filter = void> struct make_filter {
template <typename State, typename Output, typename Input,
typename EstimateUncertainty, typename ProcessUncertainty,
typename OutputUncertainty>
inline constexpr auto
static inline constexpr auto
operator()(state<State> x, [[maybe_unused]] output_t<Output> z,
[[maybe_unused]] input_t<Input> u,
estimate_uncertainty<EstimateUncertainty> p,
process_uncertainty<ProcessUncertainty> q,
output_uncertainty<OutputUncertainty> r) const {
output_uncertainty<OutputUncertainty> r) {
using kt = x_z_u_p_q_r_us_ps<State, Output, Input, empty_pack, empty_pack>;
return kt{typename kt::state{x.value},
typename kt::estimate_uncertainty{p.value},
Expand All @@ -224,14 +223,14 @@ template <typename Filter = void> struct make_filter {
template <typename State, typename Output, typename Input,
typename EstimateUncertainty, typename OutputUncertainty,
typename ProcessUncertainty, typename... Us, typename... Ps>
inline constexpr auto
static inline constexpr auto
operator()(state<State> x, [[maybe_unused]] output_t<Output> z,
[[maybe_unused]] input_t<Input> u,
estimate_uncertainty<EstimateUncertainty> p,
process_uncertainty<ProcessUncertainty> q,
output_uncertainty<OutputUncertainty> r,
[[maybe_unused]] update_types_t<Us...> uts,
[[maybe_unused]] prediction_types_t<Ps...> pts) const {
[[maybe_unused]] prediction_types_t<Ps...> pts) {

using kt =
x_z_u_p_q_r_us_ps<State, Output, Input, repack_t<update_types_t<Us...>>,
Expand All @@ -250,12 +249,12 @@ template <typename Filter = void> struct make_filter {
requires std::invocable<ProcessUncertainty, State>;
requires std::invocable<OutputUncertainty, State, Output>;
}
inline constexpr auto operator()(state<State> x,
[[maybe_unused]] output_t<Output> z,
estimate_uncertainty<EstimateUncertainty> p,
process_uncertainty<ProcessUncertainty> q,
output_uncertainty<OutputUncertainty> r,
state_transition<StateTransition> f) const {
static inline constexpr auto
operator()(state<State> x, [[maybe_unused]] output_t<Output> z,
estimate_uncertainty<EstimateUncertainty> p,
process_uncertainty<ProcessUncertainty> q,
output_uncertainty<OutputUncertainty> r,
state_transition<StateTransition> f) {
using kt = x_z_p_qq_rr_f<State, Output>;
return kt{typename kt::state{x.value},
typename kt::estimate_uncertainty{p.value},
Expand All @@ -265,10 +264,8 @@ template <typename Filter = void> struct make_filter {
}
};

template <typename Filter> inline constexpr make_filter<Filter> filter{};

template <typename... Arguments>
using filter_t = std::invoke_result_t<make_filter<>, Arguments...>;
using deduce_filter = std::invoke_result_t<filter_deducer<>, Arguments...>;
} // namespace fcarouge::internal

#endif // FCAROUGE_INTERNAL_FACTORY_HPP
2 changes: 1 addition & 1 deletion include/fcarouge/internal/kalman.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace fcarouge {
template <typename Filter>
template <typename... Arguments>
inline constexpr kalman<Filter>::kalman(Arguments... arguments)
: filter(internal::filter<implementation>(arguments...)) {}
: filter(internal::filter_deducer<Filter>::operator()(arguments...)) {}

template <typename Filter>
[[nodiscard(
Expand Down
2 changes: 1 addition & 1 deletion include/fcarouge/kalman.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ using internal::input_control;
//! @todo Should the parameter be named configurations?
//! @todo Should the configuration examples, supports be documented here?
template <typename... Arguments>
kalman(Arguments... arguments) -> kalman<internal::filter_t<Arguments...>>;
kalman(Arguments... arguments) -> kalman<internal::deduce_filter<Arguments...>>;
//! @}
} // namespace fcarouge

Expand Down

0 comments on commit 0790408

Please sign in to comment.