Skip to content

Commit 23d9b4a

Browse files
[filter] matrix type deduction independence from division (#188)
1 parent 3f4822b commit 23d9b4a

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

include/fcarouge/eigen/internal/utility.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ struct divide final {
7373
typename Eigen::Matrix<typename std::decay_t<Numerator>::Scalar,
7474
std::decay_t<Numerator>::RowsAtCompileTime, 1>;
7575

76+
//! @todo Verify the correctness this operation and others for dimensions
77+
//! and units.
7678
return result{numerator / denominator};
7779
}
7880

include/fcarouge/internal/kalman.hpp

-4
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ template <typename State, typename Output, typename Divide,
5656
typename... UpdateTypes, typename... PredictionTypes>
5757
struct kalman<State, Output, void, Divide, pack<UpdateTypes...>,
5858
pack<PredictionTypes...>> {
59-
template <typename Row, typename Column>
60-
using matrix = deduce_matrix_type_from<Divide, Row, Column>;
6159
using state = State;
6260
using output = Output;
6361
using input = empty;
@@ -187,8 +185,6 @@ template <typename State, typename Output, typename Input, typename Divide,
187185
typename... UpdateTypes, typename... PredictionTypes>
188186
struct kalman<State, Output, Input, Divide, pack<UpdateTypes...>,
189187
pack<PredictionTypes...>> {
190-
template <typename Row, typename Column>
191-
using matrix = deduce_matrix_type_from<Divide, Row, Column>;
192188
using state = State;
193189
using output = Output;
194190
using input = Input;

include/fcarouge/internal/utility.hpp

+31-9
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,39 @@ struct transpose final {
117117
}
118118
};
119119

120-
//! @todo The dimensional analysis shows the "division" of matrices gives us the
120+
//! @todo The dimensional analysis shows the deduction of matrices gives us the
121121
//! correctly sized resulting matrix but the correctness of the units have yet
122122
//! to be proven, nor whether its systematic usage is in fact appropriate.
123-
//! Hypothesis: units would be correct, usage may be incorrect, for example for
124-
//! `state_transition` may actually be unit-less and would need a unit-less
125-
//! identity denominator instead of state. Note the numerator column size and
126-
//! denominator row size are the quotient column and row sizes, respectively:
127-
//! Numerator [m by n] / Denominator [o by n] -> Quotient [m by o]
128-
template <typename Divide, typename Numerator, typename Denominator>
129-
using deduce_matrix_type_from =
130-
std::decay_t<std::invoke_result_t<Divide, Numerator, Denominator>>;
123+
//! Hypothesis: units are incorrect, usage may be incorrect, for example
124+
//! `state_transition` may actually be unit-less. Note the lhs column size and
125+
//! rhs row size are the resulting type's column and row sizes, respectively:
126+
//! Lhs [m by n] and Rhs [o by n] -> Result [m by o].
127+
//! @todo Is there a better, simpler, canonical, standard way of doing this type
128+
//! deductions?
129+
struct deducer final {
130+
template <typename Lhs, typename Rhs>
131+
[[nodiscard]] inline constexpr auto operator()(const Lhs &lhs,
132+
const Rhs &rhs) const ->
133+
typename decltype(lhs * rhs.transpose())::PlainMatrix;
134+
135+
template <typename Lhs, arithmetic Rhs>
136+
[[nodiscard]] inline constexpr auto operator()(const Lhs &lhs,
137+
const Rhs &rhs) const ->
138+
typename Lhs::PlainMatrix;
139+
140+
template <arithmetic Lhs, typename Rhs>
141+
[[nodiscard]] inline constexpr auto operator()(const Lhs &lhs,
142+
const Rhs &rhs) const ->
143+
typename decltype(rhs.transpose())::PlainMatrix;
144+
145+
template <arithmetic Lhs, arithmetic Rhs>
146+
[[nodiscard]] inline constexpr auto operator()(const Lhs &lhs,
147+
const Rhs &rhs) const
148+
-> decltype(lhs / rhs);
149+
};
150+
151+
template <typename Lhs, typename Rhs>
152+
using matrix = std::decay_t<std::invoke_result_t<deducer, Lhs, Rhs>>;
131153

132154
} // namespace fcarouge::internal
133155

0 commit comments

Comments
 (0)