@@ -42,6 +42,7 @@ For more information, please refer to <https://unlicense.org> */
42
42
// ! @file
43
43
// ! @brief Kalman filter main project header.
44
44
45
+ #include < functional>
45
46
#include < type_traits>
46
47
47
48
namespace fcarouge ::internal
@@ -50,15 +51,15 @@ namespace fcarouge::internal
50
51
extrapolate_state (const auto &x, const auto &ff, const auto &f, const auto &g,
51
52
const auto &u)
52
53
{
53
- using state = std::remove_reference_t <std:: remove_cv_t < decltype (x)> >;
54
+ using state = std::decay_t < decltype (x)>;
54
55
55
56
return state{ ff (x, f) + g * u };
56
57
}
57
58
58
59
[[nodiscard]] inline constexpr auto
59
60
extrapolate_state (const auto &x, const auto &ff, const auto &f)
60
61
{
61
- using state = std::remove_reference_t <std:: remove_cv_t < decltype (x)> >;
62
+ using state = std::decay_t < decltype (x)>;
62
63
63
64
return state{ ff (x, f) };
64
65
}
@@ -67,10 +68,8 @@ template <template <typename> class Transpose>
67
68
[[nodiscard]] inline constexpr auto
68
69
extrapolate_covariance (const auto &p, const auto &f, const auto &q)
69
70
{
70
- using estimate_uncertainty =
71
- std::remove_reference_t <std::remove_cv_t <decltype (p)>>;
72
- using state_transition =
73
- std::remove_reference_t <std::remove_cv_t <decltype (f)>>;
71
+ using estimate_uncertainty = std::decay_t <decltype (p)>;
72
+ using state_transition = std::decay_t <decltype (f)>;
74
73
75
74
Transpose<state_transition> transpose;
76
75
@@ -84,8 +83,7 @@ inline constexpr void predict(auto &x, auto &p, const auto &ff, const auto &f,
84
83
{
85
84
x = extrapolate_state (x, ff, f);
86
85
87
- using estimate_uncertainty =
88
- std::remove_reference_t <std::remove_cv_t <decltype (p)>>;
86
+ using estimate_uncertainty = std::decay_t <decltype (p)>;
89
87
90
88
Symmetrize<estimate_uncertainty> symmetrize;
91
89
@@ -99,8 +97,7 @@ inline constexpr void predict(auto &x, auto &p, const auto &ff, const auto &f,
99
97
{
100
98
x = extrapolate_state (x, ff, f, g, u);
101
99
102
- using estimate_uncertainty =
103
- std::remove_reference_t <std::remove_cv_t <decltype (p)>>;
100
+ using estimate_uncertainty = std::decay_t <decltype (p)>;
104
101
105
102
Symmetrize<estimate_uncertainty> symmetrize;
106
103
@@ -110,7 +107,7 @@ inline constexpr void predict(auto &x, auto &p, const auto &ff, const auto &f,
110
107
[[nodiscard]] inline constexpr auto update_state (const auto &x, const auto &k,
111
108
const auto &y)
112
109
{
113
- using state = std::remove_reference_t <std:: remove_cv_t < decltype (x)> >;
110
+ using state = std::decay_t < decltype (x)>;
114
111
115
112
return state{ x + k * y };
116
113
}
@@ -120,9 +117,8 @@ template <template <typename> typename Transpose,
120
117
[[nodiscard]] inline constexpr auto
121
118
update_covariance (const auto &p, const auto &k, const auto &h, const auto &r)
122
119
{
123
- using estimate_uncertainty =
124
- std::remove_reference_t <std::remove_cv_t <decltype (p)>>;
125
- using gain = std::remove_reference_t <std::remove_cv_t <decltype (k)>>;
120
+ using estimate_uncertainty = std::decay_t <decltype (p)>;
121
+ using gain = std::decay_t <decltype (k)>;
126
122
127
123
Transpose<estimate_uncertainty> transpose_p;
128
124
Transpose<gain> transpose_k;
@@ -132,39 +128,33 @@ update_covariance(const auto &p, const auto &k, const auto &h, const auto &r)
132
128
k * r * transpose_k (k) };
133
129
}
134
130
135
- template <template <typename > typename Transpose,
136
- template <typename , typename > typename Divide>
131
+ template <template <typename > typename Transpose, typename Divide>
137
132
[[nodiscard]] inline constexpr auto weight_gain (const auto &p, const auto &h,
138
133
const auto &r)
139
134
{
140
- using observation = std::remove_reference_t <std::remove_cv_t <decltype (h)>>;
141
- using output_uncertainty =
142
- std::remove_reference_t <std::remove_cv_t <decltype (r)>>;
135
+ using observation = std::decay_t <decltype (h)>;
143
136
using gain = std::invoke_result_t <Transpose<observation>, observation>;
137
+ using innovation_uncertainty = std::decay_t <decltype (r)>;
144
138
145
139
Transpose<observation> transpose_h;
146
- Divide<gain, output_uncertainty> divide;
147
-
148
- using innovation_uncertainty =
149
- std::remove_reference_t <std::remove_cv_t <decltype (r)>>;
140
+ Divide divides;
150
141
151
142
const innovation_uncertainty s{ h * p * transpose_h (h) + r };
152
143
153
- return gain{ divide (p * transpose_h (h), s) };
144
+ return gain{ divides (p * transpose_h (h), s) };
154
145
}
155
146
156
147
[[nodiscard]] inline constexpr auto innovate (const auto &x, const auto &z,
157
148
const auto &h)
158
149
{
159
- using innovation = std::remove_reference_t <std:: remove_cv_t < decltype (z)> >;
150
+ using innovation = std::decay_t < decltype (z)>;
160
151
161
152
return innovation{ z - h * x };
162
153
}
163
154
164
155
// ! @todo Do we want to allow the client to view the gain k? And the residual y?
165
156
template <template <typename > typename Transpose,
166
- template <typename > typename Symmetrize,
167
- template <typename , typename > typename Divide,
157
+ template <typename > typename Symmetrize, typename Divide,
168
158
template <typename > typename Identity>
169
159
inline constexpr void update (auto &x, auto &p, const auto &h, const auto &r,
170
160
const auto &z)
@@ -175,8 +165,7 @@ inline constexpr void update(auto &x, auto &p, const auto &h, const auto &r,
175
165
176
166
x = update_state (x, k, y);
177
167
178
- using estimate_uncertainty =
179
- std::remove_reference_t <std::remove_cv_t <decltype (p)>>;
168
+ using estimate_uncertainty = std::decay_t <decltype (p)>;
180
169
181
170
Symmetrize<estimate_uncertainty> symmetrize;
182
171
0 commit comments