Skip to content

Commit

Permalink
[filter] support input optional api
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancoisCarouge committed Feb 11, 2024
1 parent 9417e0e commit d20d9f9
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ jobs:
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: 'Install: MSVC'
uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0
with:
toolset: 14.38
- name: 'Install: GCC'
if: ${{ matrix.cxx == 'g++-13' }}
run: |
Expand Down
8 changes: 5 additions & 3 deletions include/fcarouge/internal/format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,16 @@ template <typename State, typename Output, typename Input, typename UpdateTypes,
struct std::formatter<
fcarouge::kalman<State, Output, Input, UpdateTypes, PredictionTypes>,
Char> {
using kalman =
fcarouge::kalman<State, Output, Input, UpdateTypes, PredictionTypes>;

constexpr auto parse(std::basic_format_parse_context<Char> &parse_context) {
return parse_context.begin();
}

//! @todo P2585 may be useful in simplifying and standardizing the support.
template <typename OutputIt>
auto format(const fcarouge::kalman<State, Output, Input, UpdateTypes,
PredictionTypes> &filter,
auto format(const kalman &filter,
std::basic_format_context<OutputIt, Char> &format_context) const
-> OutputIt {
format_context.advance_to(
Expand Down Expand Up @@ -96,7 +98,7 @@ struct std::formatter<
R"("q": {}, "r": {}, "s": {}, )",
filter.q(), filter.r(), filter.s()));

if constexpr (requires { filter.u(); }) {
if constexpr (fcarouge::has_input<kalman>) {
format_context.advance_to(
format_to(format_context.out(), R"("u": {}, )", filter.u()));
}
Expand Down
14 changes: 8 additions & 6 deletions include/fcarouge/internal/kalman.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,19 @@ kalman<State, Output, Input, UpdateTypes, PredictionTypes>::z() const
template <typename State, typename Output, typename Input, typename UpdateTypes,
typename PredictionTypes>
[[nodiscard("The returned control column vector U is unexpectedly "
"discarded.")]] inline constexpr auto
"discarded.")]] inline constexpr const auto &
kalman<State, Output, Input, UpdateTypes, PredictionTypes>::u() const
-> const input &requires(requires { filter.u; }) { return filter.u; }
requires(has_input<implementation>)
{
return filter.u;
}

template <typename State, typename Output, typename Input, typename UpdateTypes,
typename PredictionTypes>
[[nodiscard("The returned estimated covariance matrix P is unexpectedly "
"discarded.")]] inline constexpr auto kalman<State, Output, Input,
UpdateTypes,
PredictionTypes>::p()
const -> const estimate_uncertainty & {
"discarded.")]] inline constexpr auto
kalman<State, Output, Input, UpdateTypes, PredictionTypes>::p() const
-> const estimate_uncertainty & {
return filter.p;
}

Expand Down
4 changes: 4 additions & 0 deletions include/fcarouge/internal/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ concept algebraic = not arithmetic<Type>;
template <typename Type>
concept eigen = requires { typename Type::PlainMatrix; };

template <typename Filter>
concept has_input = requires(Filter filter) { filter.u(); } ||
requires(Filter filter) { filter.u; };

struct empty {
inline constexpr explicit empty([[maybe_unused]] auto &&...any) noexcept {
// Constructs from anything for all initializations compatibility.
Expand Down
4 changes: 2 additions & 2 deletions include/fcarouge/kalman.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,8 @@ class kalman final {
//! @return The last control column vector U.
//!
//! @complexity Constant.
inline constexpr auto u() const
-> const input &requires(requires { filter.u; });
inline constexpr const auto &u() const
requires(has_input<implementation>);

//! @brief Returns the estimated covariance matrix P.
//!
Expand Down
7 changes: 7 additions & 0 deletions include/fcarouge/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ concept algebraic = internal::algebraic<Type>;
//! @details A third party Eigen3 algebraic concept.
template <typename Type>
concept eigen = internal::eigen<Type>;

//! @brief Filter input support concept.
//!
//! @details The filter supports the input related functionality: `input` type
//! member and `u()` input method.
template <typename Filter>
concept has_input = internal::has_input<Filter>;
//! @}

//! @name Types
Expand Down

0 comments on commit d20d9f9

Please sign in to comment.