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 11, 2024
1 parent 1f2d0a0 commit d067ff0
Show file tree
Hide file tree
Showing 14 changed files with 692 additions and 15 deletions.
16 changes: 7 additions & 9 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 Down
10 changes: 6 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,24 @@ 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
1 change: 1 addition & 0 deletions include/fcarouge/kalman.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +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.
// Remove me?
using implementation = Filter;
//! @}

Expand Down
30 changes: 29 additions & 1 deletion include/fcarouge/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,33 @@ 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
//! has as many rows as the `Row` matrix, respectively for columns as the
//! `Column` matrix.
template <typename Numerator, typename Denominator>
using deduce_matrix = internal::deduce_matrix<Numerator, Denominator>;

//! @brief A string for non-type template parameters.
// TEMPLATE ON MORE THAN CHAR TYPE?
template <auto Size> struct fixed_string {
inline constexpr fixed_string(char const *elements) {
for (decltype(Size) i{0}; i < Size; ++i)
data[i] = elements[i];
}

[[nodiscard]] inline constexpr operator char const *() const { return data; }

// DO WE NEED THE +/- 1?
[[no_unique_address]] char data[Size + 1]{};
};

template <auto Size>
fixed_string(char const (&)[Size]) -> fixed_string<Size - 1>;
//! @}

//! @name Functions
Expand All @@ -174,7 +194,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 +212,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 +230,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
1 change: 1 addition & 0 deletions linalg/naive/fcarouge/linalg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ inline constexpr matrix<Type, Row, Column> zero_v<matrix<Type, Row, Column>>{};

template <typename Type, auto Row, auto Column>
[[nodiscard]] inline constexpr bool
// Shouldn't the row/column be inverted in one of the mtrix?
operator==(const matrix<Type, Row, Column> &lhs,
const matrix<Type, Row, Column> &rhs) {
for (decltype(Row) i{0}; i < Row; ++i) {
Expand Down
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 d067ff0

Please sign in to comment.