Skip to content

Commit

Permalink
[filter] support constexpr linear algebra
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancoisCarouge committed Jun 26, 2023
1 parent cf58352 commit 591a90b
Show file tree
Hide file tree
Showing 17 changed files with 872 additions and 39 deletions.
1 change: 1 addition & 0 deletions .github/workflows/cppcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ jobs:
-I benchmark/include \
-I include \
-I linalg/eigen \
-I linalg/lazy \
.
1 change: 1 addition & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
-o -iname "*.tpp" \
-o -iname "*.cpp" \
-o -iwholename "./support/format" \
-o -iwholename "./support/generator" \
-o -iwholename "./support/print" \
| xargs \
clang-format-16 --Werror --dry-run --verbose -style=file
Expand Down
5 changes: 2 additions & 3 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ FetchContent_MakeAvailable(google_benchmark)

set(PROCESSOR_AFFINITY TRUE)

foreach(BENCHMARK "baseline.cpp" "predict_1x1x0.cpp" "predict_1x1x1.cpp"
"update_1x1x0.cpp" "update_1x1x1.cpp")
foreach(BENCHMARK )
get_filename_component(NAME ${BENCHMARK} NAME_WE)
add_executable(kalman_benchmark_${NAME}_driver ${BENCHMARK})
target_include_directories(kalman_benchmark_${NAME}_driver PRIVATE "include")
Expand All @@ -70,7 +69,7 @@ foreach(BENCHMARK "baseline.cpp" "predict_1x1x0.cpp" "predict_1x1x1.cpp"
"--benchmark_out=${NAME}.json")
endforeach()

foreach(BACKEND IN ITEMS "eigen")
foreach(BACKEND IN ITEMS)
foreach(STATE_SIZE RANGE 1 2)
foreach(OUTPUT_SIZE RANGE 1 2)
configure_file(update_linalg_xx0.cpp
Expand Down
40 changes: 40 additions & 0 deletions include/fcarouge/internal/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ 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 transpose final {
template <arithmetic Arithmetic>
[[nodiscard]] inline constexpr auto
Expand All @@ -108,6 +111,11 @@ struct transpose final {
[[nodiscard]] inline constexpr auto operator()(const Matrix &value) const {
return value.transpose();
}

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

//! @todo The dimensional analysis shows the deduction of matrices gives us the
Expand All @@ -126,6 +134,38 @@ struct deducer final {
const Rhs &rhs) const
-> decltype(lhs / rhs);

// Type-erased matrix first party linear algebra support.
template <template <typename, auto, auto> typename Matrix, typename Type,
auto M, auto N, auto O>
requires(M > 1 || O > 1)
[[nodiscard]] inline constexpr auto
operator()(const Matrix<Type, M, N> &lhs, const Matrix<Type, O, N> &rhs) const
-> Matrix<Type, M, O>;

template <template <typename, auto, auto> typename Matrix, typename Type,
auto N>
[[nodiscard]] inline constexpr auto
operator()(const Matrix<Type, 1, N> &lhs, const Matrix<Type, 1, N> &rhs) const
-> Type;

template <template <typename, auto, auto> typename Lhs, typename Type, auto M>
// requires(M > 1)
[[nodiscard]] inline constexpr auto operator()(const Lhs<Type, M, 1> &lhs,
arithmetic auto rhs) const
-> Lhs<Type, M, 1>;

//! @todo Coerce type and arithmetic to be the same.
template <template <typename, auto, auto> typename Rhs, typename Type, auto O>
// requires(O > 1)
[[nodiscard]] inline constexpr auto
operator()(arithmetic auto lhs, const Rhs<Type, O, 1> &rhs) const
-> Rhs<Type, 1, O>;

// template <template <typename, auto, auto> typename Rhs, typename Type, auto
// O>
// [[nodiscard]] inline constexpr auto
// operator()(arithmetic auto lhs, const Rhs<Type, 1, 1> &rhs) const -> Type;

// Type-erased Eigen third party linear algebra support.
template <eigen Lhs, eigen Rhs>
[[nodiscard]] inline constexpr auto operator()(const Lhs &lhs,
Expand Down
4 changes: 4 additions & 0 deletions linalg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ FetchContent_MakeAvailable(eigen)
add_library(kalman_linalg_eigen INTERFACE)
target_include_directories(kalman_linalg_eigen INTERFACE "eigen")
target_link_libraries(kalman_linalg_eigen INTERFACE Eigen3::Eigen kalman)

add_library(kalman_linalg_lazy INTERFACE)
target_include_directories(kalman_linalg_lazy INTERFACE "lazy")
target_link_libraries(kalman_linalg_lazy INTERFACE kalman kalman_generator)
Loading

0 comments on commit 591a90b

Please sign in to comment.