Skip to content

Commit

Permalink
[tidy] tighten rules
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancoisCarouge committed May 21, 2022
1 parent 9358a3d commit a919b8e
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 299 deletions.
14 changes: 9 additions & 5 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
Checks: '*,
-fuchsia-overloaded-operator,
-misc-non-private-member-variables-in-classes,
-llvmlibc-*,
-modernize-use-trailing-return-type,
-altera-struct-pack-align,
-fuchsia-trailing-return'
-fuchsia-overloaded-operator,
-fuchsia-trailing-return,
-llvmlibc-implementation-in-namespace,
-llvmlibc-restrict-system-libc-headers,
-portability-simd-intrinsics'

CheckOptions:
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: 1
4 changes: 2 additions & 2 deletions .github/workflows/verify_code_static_analysis_tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
run: sudo apt update
- name: Install
run: |
sudo apt install clang-tidy-12
sudo apt install clang-tidy-13
( cd /tmp ; mkdir eigen ;
git clone --depth 1 https://gitlab.com/libeigen/eigen.git ;
( cd eigen ;
Expand All @@ -28,6 +28,6 @@ jobs:
- name: Tidy
run: |
FILES=`find . -iname *.hpp`
clang-tidy-12 ${FILES} \
clang-tidy-13 ${FILES} \
--warnings-as-errors=* \
-- -x c++ -Wall -Wextra -pedantic -std=c++2b -Iinclude -I/usr/local/include/eigen3
49 changes: 39 additions & 10 deletions include/fcarouge/internal/kalman.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,14 @@ For more information, please refer to <https://unlicense.org> */
//! @file
//! @brief The main Kalman filter class.

#include "kalman_equation.hpp"
#include "kalman_operator.hpp"

#include <functional>
#include <type_traits>

namespace fcarouge::internal
{
template <typename State, typename Output, typename Input, typename Transpose,
typename Symmetrize, typename Divide, typename Identity,
typename... PredictionArguments>
typename Multiply, typename... PredictionArguments>
struct kalman {
//! @name Public Member Types
//! @{
Expand Down Expand Up @@ -94,12 +91,18 @@ struct kalman {
//! @details Also known as B.
using input_control = std::invoke_result_t<Divide, State, Input>;

using innovation = output;
using innovation_uncertainty = output_uncertainty;
using gain = std::invoke_result_t<Transpose, output_model>;

//! @}

//! @name Public Member Variables
//! @{

//! @brief The state estimate vector x.
//!
//! @todo Is there a simpler, more portable way to get a zero initialization?
state x{ 0 * Identity().template operator()<state>() };

//! @brief The estimate uncertainty, covariance matrix P.
Expand Down Expand Up @@ -167,38 +170,64 @@ struct kalman {
//! @details
// Add prediction arguments?
std::function<state(const state &, const state_transition &)> predict_state =
[](const state &x, const state_transition &f) { return state{ f * x }; };
[this](const state &x, const state_transition &f) {
return state{ multiply(f, x) };
};

Transpose transpose;
Divide divide;
Symmetrize symmetrize;
Identity identity;
Multiply multiply;

//! @}

//! @name Public Member Functions
//! @{

//! @todo Do we want to allow the client to view the gain k? And the residual
//! y?
//! @todo Do we want to store i - k * h in a temporary result for reuse?
inline constexpr void update(const auto &...output_z)
{
const auto z{ output{ output_z... } };

h = transition_observation_h();
r = noise_observation_r();
const auto z{ output{ output_z... } };
internal::update<Transpose, Symmetrize, Divide, Identity>(x, p, h, r, z);

const innovation_uncertainty s{ h * p * transpose(h) + r };
const gain k{ divide(p * transpose(h), s) };
const innovation y{ z - h * x };
const auto i{ identity.template operator()<estimate_uncertainty>() };

x = state{ x + k * y };
p = symmetrize(estimate_uncertainty{
(i - k * h) * p * transpose(i - k * h) + k * r * transpose(k) });
}

inline constexpr void predict(const PredictionArguments &...arguments,
const auto &...input_u)
{
const auto ff{ predict_state };
const auto u{ input{ input_u... } };

f = transition_state_f(arguments...);
q = noise_process_q(arguments...);
g = transition_control_g(arguments...);
const auto u{ input{ input_u... } };
internal::predict<Transpose, Symmetrize>(x, p, ff, f, q, g, u);

x = state{ ff(x, f) + g * u };
p = symmetrize(estimate_uncertainty{ f * p * transpose(f) + q });
}

inline constexpr void predict(const PredictionArguments &...arguments)
{
const auto ff{ predict_state };

f = transition_state_f(arguments...);
q = noise_process_q(arguments...);
internal::predict<Transpose, Symmetrize>(x, p, ff, f, q);

x = state{ ff(x, f) };
p = symmetrize(estimate_uncertainty{ f * p * transpose(f) + q });
}

//! @}
Expand Down
165 changes: 0 additions & 165 deletions include/fcarouge/internal/kalman_equation.hpp

This file was deleted.

6 changes: 3 additions & 3 deletions include/fcarouge/internal/kalman_operator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ For more information, please refer to <https://unlicense.org> */

namespace fcarouge::internal
{
//! @brief Function object for providing an identy matrix.
//! @brief Function object for providing an identity matrix.
//!
//! @note This function object template should be a variable template. Proposed
//! in paper P2008R0 entitled "Enabling variable template template parameters".
Expand All @@ -55,9 +55,9 @@ struct identity {
//!
//! @return The identity matrix `diag(1, 1, ..., 1)`.
template <typename Type>
[[nodiscard]] inline constexpr Type operator()() const noexcept
[[nodiscard]] inline constexpr auto operator()() const noexcept
{
return 1;
return Type{ 1 };
}
};

Expand Down

0 comments on commit a919b8e

Please sign in to comment.