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 28, 2024
1 parent dcec735 commit e9aabc0
Show file tree
Hide file tree
Showing 13 changed files with 950 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/cppcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@ jobs:
-I support/eigen \
-I support/generator \
-I support/lazy \
-I support/mp_units \
-I support/naive \
-I support/physical \
.
26 changes: 20 additions & 6 deletions include/fcarouge/internal/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,17 +259,24 @@ struct transposer final {
return value;
}

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

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

// How to, should we force external type to provide a transposition
// implementation if the type needs to, should be transposed?
template <typename Type>
[[nodiscard]] inline constexpr auto operator()(const Type &value) const {
return value;
}
};

struct matrix_deducer;
Expand All @@ -287,6 +294,13 @@ struct matrix_deducer final {
requires(eigen<Lhs> or eigen<Rhs>)
[[nodiscard]] inline constexpr auto operator()(Lhs lhs, Rhs rhs) const ->
typename decltype(lhs * transposer{}(rhs))::PlainMatrix;

template <template <typename, typename, typename> typename T, typename M1,
typename R1, typename M2, typename R2, typename C>
requires(eigen<M1> or eigen<M2>)
[[nodiscard]] inline constexpr auto
operator()(T<M1, R1, C> lhs,
T<M2, R2, C> rhs) const -> T<deduce_matrix<M1, M2>, R1, R2>;
};

using empty_tuple = std::tuple<>;
Expand Down
7 changes: 5 additions & 2 deletions include/fcarouge/internal/x_z_p_r_f.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ 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;
// Refactor deduce into a deduce_product and deduce_quotient.
using gain =
std::remove_cvref_t<decltype(std::declval<estimate_uncertainty>() /
std::declval<innovation_uncertainty>())>;

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

state x{zero_v<state>};
estimate_uncertainty p{identity_v<estimate_uncertainty>};
Expand Down
2 changes: 1 addition & 1 deletion sample/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ 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> ]]

return() # REMOVE ME
foreach(SAMPLE "kf_1x1x0_building_height.cpp" "kf_1x1x0_liquid_temperature.cpp"
"kf_1x1x1_dog_position.cpp")
get_filename_component(NAME ${SAMPLE} NAME_WE)
Expand Down
2 changes: 2 additions & 0 deletions support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ For more information, please refer to <https://unlicense.org> ]]

add_subdirectory("eigen")
add_subdirectory("main")
add_subdirectory("mp_units")
add_subdirectory("naive")
add_subdirectory("physical")

add_library(kalman_options INTERFACE)

Expand Down
16 changes: 7 additions & 9 deletions support/eigen/fcarouge/linalg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ constexpr auto operator/(const Numerator &lhs, const Denominator &rhs)
} // namespace fcarouge

//! @brief Specialization of the standard formatter for the Eigen matrix.
template <typename Type, auto Row, auto Column, typename Char>
struct std::formatter<fcarouge::matrix<Type, Row, Column>, Char> {
template <fcarouge::eigen Matrix, typename Char>
struct std::formatter<Matrix, Char> {
constexpr auto parse(std::basic_format_parse_context<Char> &parse_context) {
return parse_context.begin();
}

template <typename OutputIterator>
constexpr auto
format(const fcarouge::matrix<Type, Row, Column> &value,
format(const Matrix &value,
std::basic_format_context<OutputIterator, Char> &format_context) const
-> OutputIterator {
const Eigen::IOFormat output_format{Eigen::StreamPrecision,
Expand All @@ -123,11 +123,10 @@ struct std::formatter<fcarouge::matrix<Type, Row, Column>, Char> {

template <typename OutputIterator>
constexpr auto
format(const fcarouge::matrix<Type, Row, Column> &value,
format(const Matrix &value,
std::basic_format_context<OutputIterator, Char> &format_context) const
-> OutputIterator
requires(fcarouge::matrix<Type, Row, Column>::RowsAtCompileTime == 1 &&
fcarouge::matrix<Type, Row, Column>::ColsAtCompileTime != 1)
requires(Matrix::RowsAtCompileTime == 1 && Matrix::ColsAtCompileTime != 1)
{
const Eigen::IOFormat output_format{Eigen::StreamPrecision,
Eigen::DontAlignCols,
Expand All @@ -146,11 +145,10 @@ struct std::formatter<fcarouge::matrix<Type, Row, Column>, Char> {

template <typename OutputIterator>
constexpr auto
format(const fcarouge::matrix<Type, Row, Column> &value,
format(const Matrix &value,
std::basic_format_context<OutputIterator, Char> &format_context) const
-> OutputIterator
requires(fcarouge::matrix<Type, Row, Column>::RowsAtCompileTime == 1 &&
fcarouge::matrix<Type, Row, Column>::ColsAtCompileTime == 1)
requires(Matrix::RowsAtCompileTime == 1 && Matrix::ColsAtCompileTime == 1)
{
return std::format_to(format_context.out(), "{}", value.value());
}
Expand Down
71 changes: 71 additions & 0 deletions support/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)
77 changes: 77 additions & 0 deletions support/mp_units/fcarouge/unit.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/* __ _ __ __ _ _
| |/ / /\ | | | \/ | /\ | \ | |
| ' / / \ | | | \ / | / \ | \| |
| < / /\ \ | | | |\/| | / /\ \ | . ` |
| . \ / ____ \| |____| | | |/ ____ \| |\ |
|_|\_\/_/ \_\______|_| |_/_/ \_\_| \_|
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/format.h>
#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()};

template <mp_units::Quantity Type>
[[nodiscard]] inline constexpr auto transpose(const Type &value) {
return value;
}
} // 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::m2;
using mp_units::si::unit_symbols::s;
using mp_units::si::unit_symbols::s2;
using mp_units::si::unit_symbols::s3;
inline constexpr auto s4 = pow<4>(second);

template <typename Scalar> using distance_t = mp_units::quantity<m, Scalar>;

template <typename Scalar> using velocity_t = mp_units::quantity<m / s, Scalar>;

template <typename Scalar>
using acceleration_t = mp_units::quantity<m / s2, Scalar>;

#endif // FCAROUGE_UNIT_HPP
45 changes: 45 additions & 0 deletions support/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 e9aabc0

Please sign in to comment.