@@ -117,17 +117,39 @@ struct transpose final {
117
117
}
118
118
};
119
119
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
121
121
// ! correctly sized resulting matrix but the correctness of the units have yet
122
122
// ! 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>>;
131
153
132
154
} // namespace fcarouge::internal
133
155
0 commit comments