Skip to content

Commit

Permalink
[filter] add internal deducer Eigen3 concept support (#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancoisCarouge authored Apr 21, 2023
1 parent babad2e commit d650687
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions include/fcarouge/internal/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ concept arithmetic = std::integral<Type> || std::floating_point<Type>;
template <typename Type>
concept algebraic = not arithmetic<Type>;

template <typename Type>
concept eigen = requires {
typename Type::PlainMatrix;
};

struct empty {
inline constexpr explicit empty([[maybe_unused]] auto &&...any) noexcept {
// Constructs from anything for all initializations compatibility.
Expand Down Expand Up @@ -122,36 +127,30 @@ struct transpose final {
//! correctly sized resulting matrix but the correctness of the units have yet
//! to be proven, nor whether its systematic usage is in fact appropriate.
//! Hypothesis: units are incorrect, usage may be incorrect, for example
//! `state_transition` may actually be unit-less. Note the lhs column size and
//! rhs row size are the resulting type's column and row sizes, respectively:
//! `state_transition` may actually be unit-less. Note the `lhs` column size and
//! `rhs` row size are the resulting type's column and row sizes, respectively:
//! Lhs [m by n] and Rhs [o by n] -> Result [m by o].
//! @todo Is there a better, simpler, canonical, standard way of doing this type
//! deductions?
//! deduction?
struct deducer final {
// Built-in's types deductions.
// Built-in, arithmetic, standard division support.
template <arithmetic Lhs, arithmetic Rhs>
[[nodiscard]] inline constexpr auto operator()(const Lhs &lhs,
const Rhs &rhs) const
-> decltype(lhs / rhs);

// Eigen's types deductions.
template <typename Lhs, typename Rhs>
requires requires(Lhs lhs, Rhs rhs) {
typename Lhs::PlainMatrix;
typename Lhs::PlainMatrix;
}
// Type-erased Eigen third party linear algebra support.
template <eigen Lhs, eigen Rhs>
[[nodiscard]] inline constexpr auto operator()(const Lhs &lhs,
const Rhs &rhs) const ->
typename decltype(lhs * rhs.transpose())::PlainMatrix;

template <typename Lhs, arithmetic Rhs>
requires requires(Lhs lhs) { typename Lhs::PlainMatrix; }
template <eigen Lhs, arithmetic Rhs>
[[nodiscard]] inline constexpr auto operator()(const Lhs &lhs,
const Rhs &rhs) const ->
typename Lhs::PlainMatrix;

template <arithmetic Lhs, typename Rhs>
requires requires(Rhs rhs) { typename Rhs::PlainMatrix; }
template <arithmetic Lhs, eigen Rhs>
[[nodiscard]] inline constexpr auto operator()(const Lhs &lhs,
const Rhs &rhs) const ->
typename decltype(rhs.transpose())::PlainMatrix;
Expand Down

0 comments on commit d650687

Please sign in to comment.