@@ -36,22 +36,30 @@ OTHER DEALINGS IN THE SOFTWARE.
36
36
37
37
For more information, please refer to <https://unlicense.org> */
38
38
39
- #ifndef FCAROUGE_INTERNAL_KALMAN_EIGEN_OPERATOR_HPP
40
- #define FCAROUGE_INTERNAL_KALMAN_EIGEN_OPERATOR_HPP
39
+ #ifndef FCAROUGE_INTERNAL_KALMAN_EIGEN_HPP
40
+ #define FCAROUGE_INTERNAL_KALMAN_EIGEN_HPP
41
41
42
42
// ! @file
43
43
// ! @brief Kalman operation for Eigen 3 types.
44
44
// !
45
- // ! @details Default customization point objects (CPO) for Eigen 3 types .
45
+ // ! @details Default customization point objects (CPO).
46
46
47
- #include " kalman.hpp"
47
+ #include " fcarouge/ kalman.hpp"
48
48
49
49
#include < Eigen/Eigen>
50
50
51
+ #include < concepts>
52
+ #include < cstddef>
53
+ #include < functional>
51
54
#include < type_traits>
52
55
53
56
namespace fcarouge ::eigen::internal
54
57
{
58
+
59
+ // ! @brief Arithmetic concept.
60
+ template <typename Type>
61
+ concept arithmetic = std::integral<Type> || std::floating_point<Type>;
62
+
55
63
// ! @brief Function object for performing Eigen matrix transposition.
56
64
// !
57
65
// ! @details Implemented with the Eigen linear algebra library matrices with
@@ -78,7 +86,7 @@ struct transpose {
78
86
// ! @details Implemented with the Eigen linear algebra library matrices with
79
87
// ! sizes fixed at compile-time.
80
88
struct symmetrize {
81
- // ! @brief Returns the symmetrised `value`.
89
+ // ! @brief Returns the symmetrized `value`.
82
90
// !
83
91
// ! @param value Value to compute the symmetry of.
84
92
// !
@@ -101,7 +109,7 @@ struct divide {
101
109
// ! @param numerator The dividend matrix of the division. N: m x n
102
110
// ! @param denominator The divisor matrix of the division. D: o x n
103
111
// !
104
- // ! @return The quotien matrix. Q: m x o
112
+ // ! @return The quotient matrix. Q: m x o
105
113
// !
106
114
// ! @exception May throw implementation-defined exceptions.
107
115
// !
@@ -119,18 +127,77 @@ struct divide {
119
127
.solve (numerator.transpose ())
120
128
.transpose ();
121
129
}
130
+
131
+ // ! @brief Returns the quotient of `numerator` and `denominator`.
132
+ // !
133
+ // ! @param numerator The dividend matrix of the division. N: m x 1
134
+ // ! @param denominator The divisor value of the division.
135
+ // !
136
+ // ! @return The quotient column vector. Q: m x 1
137
+ // !
138
+ // ! @exception May throw implementation-defined exceptions.
139
+ // !
140
+ // ! @todo Simplify implementation.
141
+ [[nodiscard]] inline constexpr auto
142
+ operator ()(const auto &numerator, const arithmetic auto &denominator) const ->
143
+ typename Eigen::Vector<
144
+ typename std::decay_t <decltype(numerator)>::Scalar,
145
+ std::decay_t <decltype(numerator)>::RowsAtCompileTime>
146
+ {
147
+ return Eigen::Matrix<typename std::decay_t <decltype (numerator)>::Scalar, 1 ,
148
+ 1 >{ denominator }
149
+ .transpose ()
150
+ .fullPivHouseholderQr ()
151
+ .solve (numerator.transpose ())
152
+ .transpose ();
153
+ }
154
+
155
+ // ! @brief Returns the quotient of `numerator` and `denominator`.
156
+ // !
157
+ // ! @param numerator The dividend value of the division.
158
+ // ! @param denominator The divisor matrix of the division. D: o x 1
159
+ // !
160
+ // ! @return The quotient row vector. Q: 1 x o
161
+ // !
162
+ // ! @exception May throw implementation-defined exceptions.
163
+ // !
164
+ // ! @todo Simplify implementation.
165
+ [[nodiscard]] inline constexpr auto
166
+ operator ()(const arithmetic auto &numerator, const auto &denominator) const ->
167
+ typename Eigen::RowVector<
168
+ typename std::decay_t <decltype(denominator)>::Scalar,
169
+ std::decay_t <decltype(denominator)>::RowsAtCompileTime>
170
+ {
171
+ return denominator.transpose ()
172
+ .fullPivHouseholderQr ()
173
+ .solve (Eigen::Matrix<typename std::decay_t <decltype (numerator)>::Scalar,
174
+ 1 , 1 >{ numerator })
175
+ .transpose ();
176
+ }
177
+
178
+ // ! @brief Returns the quotient of `numerator` and `denominator`.
179
+ // !
180
+ // ! @param numerator The dividend value of the division.
181
+ // ! @param denominator The divisor value of the division.
182
+ // !
183
+ // ! @return The quotient value.
184
+ [[nodiscard]] inline constexpr auto
185
+ operator ()(const arithmetic auto &numerator,
186
+ const arithmetic auto &denominator) const
187
+ {
188
+ return numerator / denominator;
189
+ }
122
190
};
123
191
124
192
// ! @brief Function object for providing an Eigen identity matrix.
125
193
// !
126
194
// ! @details Implemented with the Eigen linear algebra library matrices with
127
195
// ! sizes fixed at compile-time.
128
196
// !
129
- // ! @note Could this function object template be replaced by a variable
130
- // ! template? Proposed in paper P2008R0 entitled "Enabling variable template
131
- // ! template parameters".
132
- struct identity {
133
- // ! @brief Returns the identity maxtrix.
197
+ // ! @note Could this function object template be a variable template as proposed
198
+ // ! in paper P2008R0 entitled "Enabling variable template template parameters"?
199
+ struct identity_matrix {
200
+ // ! @brief Returns the identity matrix.
134
201
// !
135
202
// ! @tparam Type The type template parameter of the matrix.
136
203
// !
@@ -142,8 +209,28 @@ struct identity {
142
209
{
143
210
return Type::Identity ();
144
211
}
212
+
213
+ // ! @brief Returns `1`, the 1-by-1 identity matrix equivalent.
214
+ // !
215
+ // ! @tparam Type The type template parameter of the value.
216
+ // !
217
+ // ! @return The value `1`.
218
+ template <arithmetic Type>
219
+ [[nodiscard]] inline constexpr auto operator ()() const noexcept
220
+ {
221
+ return Type{ 1 };
222
+ }
145
223
};
146
224
225
+ template <typename Type = double , std::size_t State = 1 , std::size_t Output = 1 ,
226
+ std::size_t Input = 1 , typename UpdateArguments = std::tuple<>,
227
+ typename PredictionArguments = std::tuple<>>
228
+ using kalman = fcarouge::kalman<
229
+ Type, std::conditional_t <State == 1 , Type, Eigen::Vector<Type, State>>,
230
+ std::conditional_t <Output == 1 , Type, Eigen::Vector<Type, Output>>,
231
+ std::conditional_t <Input == 1 , Type, Eigen::Vector<Type, Input>>, transpose,
232
+ symmetrize, divide, identity_matrix, UpdateArguments, PredictionArguments>;
233
+
147
234
} // namespace fcarouge::eigen::internal
148
235
149
- #endif // FCAROUGE_INTERNAL_KALMAN_EIGEN_OPERATOR_HPP
236
+ #endif // FCAROUGE_INTERNAL_KALMAN_EIGEN_HPP
0 commit comments