Skip to content

Commit

Permalink
[compatibility] mp-units support test
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancoisCarouge committed Nov 16, 2024
1 parent 1f2d0a0 commit 6696e99
Show file tree
Hide file tree
Showing 13 changed files with 480 additions and 20 deletions.
30 changes: 17 additions & 13 deletions include/fcarouge/internal/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ template <typename Pack> using repack_t = repack<Pack>::type;

template <typename Pack> inline constexpr auto size{repack<Pack>::size};

template <typename Pack>
using size_t = std::remove_const_t<decltype(size<Pack>)>;

template <typename Type, typename... Types> struct first_type {
using type = Type;
};
Expand Down Expand Up @@ -272,27 +275,22 @@ template <typename Type> struct not_implemented {
static_assert(none, "This type is not implemented. See message.");
};

inline constexpr auto adl_transpose{
[](const auto &value) { return transpose(value); }};

struct transposer final {
template <arithmetic Arithmetic>
[[nodiscard]] inline constexpr auto
operator()(const Arithmetic &value) const {
template <typename Type>
[[nodiscard]] inline constexpr auto operator()(const Type &value) const {
return value;
}

//! @todo Remove and always rely on ADL and require implementation in linear
//! algebra support?
template <typename Matrix>
requires requires(Matrix value) { value.transpose(); }
[[nodiscard]] inline constexpr auto operator()(const Matrix &value) const {
return value.transpose();
}

template <typename Matrix>
requires requires(Matrix value) { transpose(value); }
[[nodiscard]] inline constexpr auto operator()(const Matrix &value) const {
return adl_transpose(value);
return transpose(value);
}
};

Expand All @@ -301,18 +299,24 @@ struct matrix_deducer final {
[[nodiscard]] inline constexpr auto
operator()(Lhs lhs, Rhs rhs) const -> decltype(lhs * transposer{}(rhs));

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

template <typename Lhs, eigen Rhs>
[[nodiscard]] inline constexpr auto operator()(Lhs lhs, Rhs rhs) const ->
typename decltype(lhs * transposer{}(rhs))::PlainMatrix;
// Combine C1 and C2 in C?
template <template <typename, typename, typename> typename T, typename M1,
typename R1, typename C1, typename M2, typename R2, typename C2>
requires(eigen<M1> or eigen<M2>)
[[nodiscard]] inline constexpr auto operator()(T<M1, R1, C1> lhs,
T<M2, R2, C2> rhs) const
-> T<typename decltype(M1{} * transposer{}(M2{}))::PlainMatrix, R1, R2>;
};

template <typename Lhs, typename Rhs>
using deduce_matrix =
std::remove_cvref_t<std::invoke_result_t<matrix_deducer, Lhs, Rhs>>;

} // namespace fcarouge::internal

#endif // FCAROUGE_INTERNAL_UTILITY_HPP
8 changes: 4 additions & 4 deletions include/fcarouge/internal/x_z_p_r_f.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,22 @@ template <typename State, typename Output> struct x_z_p_r_f {
using estimate_uncertainty = deduce_matrix<state, state>;
using output_uncertainty = deduce_matrix<output, output>;
using state_transition = deduce_matrix<state, state>;
using gain = deduce_matrix<state, output>;
using innovation = output;
using innovation_uncertainty = output_uncertainty;

static inline const auto i{identity_v<deduce_matrix<state, state>>};

state x{zero_v<state>};
estimate_uncertainty p{identity_v<estimate_uncertainty>};
output_uncertainty r{zero_v<output_uncertainty>};
state_transition f{identity_v<state_transition>};
gain k{identity_v<gain>};
innovation y{zero_v<innovation>};
innovation_uncertainty s{identity_v<innovation_uncertainty>};
output z{zero_v<output>};
transposer t{};

using gain = std::remove_cvref_t<decltype(p / s)>;
gain k{identity_v<gain>};
static inline const auto i{identity_v<gain>};

inline constexpr void update(const output &output_z) {
z = output_z;
s = p + r;
Expand Down
2 changes: 1 addition & 1 deletion include/fcarouge/kalman.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class kalman : public internal::conditional_member_types<Filter> {
//! @details The internal implementation, filtering strategies, and presence
//! of members vary based on the constructed, configured, declared, deduced
//! filter.
using implementation = Filter;
using implementation = Filter; // Remove me (?) in a separate pull request.
//! @}

//! @name Private Member Variables
Expand Down
13 changes: 12 additions & 1 deletion include/fcarouge/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ using empty_pack = internal::empty_pack;
//! @brief Unpack the first type of the type template parameter pack.
template <typename... Types> using first_t = internal::first_t<Types...>;

//! @brief Type of the count of the types in the pack.
template <typename Pack> using size_t = internal::size_t<Pack>;

//! @brief The matrix type satisfying `X * Row = Column`.
//!
//! @details The resulting type of a matrix division. The resulting matrix type
Expand Down Expand Up @@ -174,7 +177,7 @@ constexpr auto operator/(const Numerator &lhs, const Denominator &rhs)
template <auto... Values>
inline constexpr auto first_v{internal::first_v<Values...>};

//! @brief Count of packed types.
//! @brief Count the packed types.
template <typename Pack> inline constexpr auto size{internal::size<Pack>};

//! @brief The identity matrix.
Expand All @@ -192,6 +195,10 @@ template <typename Type>
requires requires { Type::Identity(); }
inline auto identity_v<Type>{Type::Identity()};

template <typename Type>
requires requires { Type::identity(); }
inline auto identity_v<Type>{Type::identity()};

//! @brief The zero matrix.
//!
//! @details User-defined.
Expand All @@ -206,6 +213,10 @@ inline constexpr Arithmetic zero_v<Arithmetic>{0};
template <typename Type>
requires requires { Type::Zero(); }
inline auto zero_v<Type>{Type::Zero()};

template <typename Type>
requires requires { Type::zero(); }
inline auto zero_v<Type>{Type::zero()};
//! @}
} // namespace fcarouge

Expand Down
2 changes: 2 additions & 0 deletions linalg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org> ]]

add_subdirectory("eigen")
add_subdirectory("mp_units")
add_subdirectory("naive")
add_subdirectory("physical")
71 changes: 71 additions & 0 deletions linalg/mp_units/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#[[ __ _ __ __ _ _
| |/ / /\ | | | \/ | /\ | \ | |
| ' / / \ | | | \ / | / \ | \| |
| < / /\ \ | | | |\/| | / /\ \ | . ` |
| . \ / ____ \| |____| | | |/ ____ \| |\ |
|_|\_\/_/ \_\______|_| |_/_/ \_\_| \_|
Kalman Filter
Version 0.4.0
https://github.com/FrancoisCarouge/Kalman
SPDX-License-Identifier: Unlicense
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org> ]]

include(FetchContent)

FetchContent_Declare(
fmt
GIT_REPOSITORY "https://github.com/fmtlib/fmt"
GIT_SHALLOW TRUE
FIND_PACKAGE_ARGS NAMES fmt)
FetchContent_MakeAvailable(fmt)

FetchContent_Declare(
gsl-lite
GIT_REPOSITORY "https://github.com/gsl-lite/gsl-lite"
GIT_SHALLOW TRUE
FIND_PACKAGE_ARGS NAMES gsl-lite)
FetchContent_MakeAvailable(gsl-lite)

FetchContent_Declare(
mp-units
GIT_REPOSITORY "https://github.com/mpusz/mp-units"
GIT_SHALLOW TRUE
SOURCE_SUBDIR "src" FIND_PACKAGE_ARGS NAMES mp-units)
FetchContent_MakeAvailable(mp-units)

target_compile_options(mp-units INTERFACE $<IF:$<CXX_COMPILER_ID:MSVC>, ,
-Wno-double-promotion>)
target_compile_options(mp-units INTERFACE $<IF:$<CXX_COMPILER_ID:MSVC>, ,
-Wno-undef>)

add_library(kalman_unit_mp_units INTERFACE)
target_sources(
kalman_unit_mp_units INTERFACE FILE_SET "unit_headers" TYPE "HEADERS" FILES
"fcarouge/unit.hpp")
target_link_libraries(kalman_unit_mp_units INTERFACE mp-units::mp-units)
61 changes: 61 additions & 0 deletions linalg/mp_units/fcarouge/unit.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* __ _ __ __ _ _
| |/ / /\ | | | \/ | /\ | \ | |
| ' / / \ | | | \ / | / \ | \| |
| < / /\ \ | | | |\/| | / /\ \ | . ` |
| . \ / ____ \| |____| | | |/ ____ \| |\ |
|_|\_\/_/ \_\______|_| |_/_/ \_\_| \_|
Kalman Filter
Version 0.4.0
https://github.com/FrancoisCarouge/Kalman
SPDX-License-Identifier: Unlicense
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org> */

#ifndef FCAROUGE_UNIT_HPP
#define FCAROUGE_UNIT_HPP

#include <mp-units/framework/quantity.h>
#include <mp-units/math.h>
#include <mp-units/systems/si.h>

namespace fcarouge {
//! @brief The physical unit quantity.
template <auto Reference, typename Representation>
using quantity = mp_units::quantity<Reference, Representation>;

template <mp_units::Quantity Type>
inline constexpr auto identity_v<Type>{Type::one()};
} // namespace fcarouge

using mp_units::si::metre;
using mp_units::si::second;
using mp_units::si::unit_symbols::m;
using mp_units::si::unit_symbols::s;
using mp_units::si::unit_symbols::s2;

#endif // FCAROUGE_UNIT_HPP
45 changes: 45 additions & 0 deletions linalg/physical/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#[[ __ _ __ __ _ _
| |/ / /\ | | | \/ | /\ | \ | |
| ' / / \ | | | \ / | / \ | \| |
| < / /\ \ | | | |\/| | / /\ \ | . ` |
| . \ / ____ \| |____| | | |/ ____ \| |\ |
|_|\_\/_/ \_\______|_| |_/_/ \_\_| \_|
Kalman Filter
Version 0.4.0
https://github.com/FrancoisCarouge/Kalman
SPDX-License-Identifier: Unlicense
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org> ]]

add_library(kalman_physical_linalg_mp_units_eigen INTERFACE)
target_sources(
kalman_physical_linalg_mp_units_eigen
INTERFACE FILE_SET "unit_headers" TYPE "HEADERS" FILES
"fcarouge/physical_linalg.hpp")
target_link_libraries(kalman_physical_linalg_mp_units_eigen
INTERFACE kalman kalman_unit_mp_units kalman_linalg_eigen)
Loading

0 comments on commit 6696e99

Please sign in to comment.