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 16, 2023
1 parent 8f0cc91 commit 0286956
Show file tree
Hide file tree
Showing 14 changed files with 581 additions and 101 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
103 changes: 42 additions & 61 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,65 +54,46 @@ FetchContent_MakeAvailable(google_benchmark)

set(PROCESSOR_AFFINITY TRUE)

foreach(BENCHMARK "baseline.cpp" "predict_1x1x0.cpp" "predict_1x1x1.cpp"
"update_1x1x0.cpp" "update_1x1x1.cpp")
get_filename_component(NAME ${BENCHMARK} NAME_WE)
add_executable(kalman_benchmark_${NAME}_driver ${BENCHMARK})
target_include_directories(kalman_benchmark_${NAME}_driver PRIVATE "include")
set_target_properties(kalman_benchmark_${NAME}_driver PROPERTIES CXX_STANDARD
23)
set_target_properties(kalman_benchmark_${NAME}_driver
PROPERTIES CXX_EXTENSIONS OFF)
target_link_libraries(
kalman_benchmark_${NAME}_driver PRIVATE benchmark::benchmark
benchmark::benchmark_main kalman)
add_test(kalman_benchmark_${NAME} kalman_benchmark_${NAME}_driver
"--benchmark_out=${NAME}.json")
endforeach()
# foreach(BENCHMARK "baseline.cpp" "predict_1x1x0.cpp" "predict_1x1x1.cpp"
# "update_1x1x0.cpp" "update_1x1x1.cpp") get_filename_component(NAME
# ${BENCHMARK} NAME_WE) add_executable(kalman_benchmark_${NAME}_driver
# ${BENCHMARK}) target_include_directories(kalman_benchmark_${NAME}_driver
# PRIVATE "include") set_target_properties(kalman_benchmark_${NAME}_driver
# PROPERTIES CXX_STANDARD 23)
# set_target_properties(kalman_benchmark_${NAME}_driver PROPERTIES
# CXX_EXTENSIONS OFF) target_link_libraries( kalman_benchmark_${NAME}_driver
# PRIVATE benchmark::benchmark benchmark::benchmark_main kalman)
# add_test(kalman_benchmark_${NAME} kalman_benchmark_${NAME}_driver
# "--benchmark_out=${NAME}.json") endforeach()

foreach(BACKEND IN ITEMS "eigen")
foreach(STATE_SIZE RANGE 1 2)
foreach(OUTPUT_SIZE RANGE 1 2)
configure_file(update_linalg_xx0.cpp
update_linalg_${STATE_SIZE}x${OUTPUT_SIZE}x0.cpp)
get_filename_component(
NAME update_linalg_${STATE_SIZE}x${OUTPUT_SIZE}x0.cpp NAME_WE)
add_executable(kalman_benchmark_${BACKEND}_${NAME}_driver
update_linalg_${STATE_SIZE}x${OUTPUT_SIZE}x0.cpp)
target_include_directories(kalman_benchmark_${BACKEND}_${NAME}_driver
PRIVATE "include")
set_target_properties(kalman_benchmark_${BACKEND}_${NAME}_driver
PROPERTIES CXX_STANDARD 23)
set_target_properties(kalman_benchmark_${BACKEND}_${NAME}_driver
PROPERTIES CXX_EXTENSIONS OFF)
target_link_libraries(
kalman_benchmark_${BACKEND}_${NAME}_driver
PRIVATE benchmark::benchmark benchmark::benchmark_main kalman
kalman_linalg_${BACKEND})
add_test(kalman_benchmark_${BACKEND}_${NAME}
kalman_benchmark_${BACKEND}_${NAME}_driver
"--benchmark_out=${NAME}.json")
endforeach()
foreach(INPUT_SIZE RANGE 1 2)
configure_file(predict_linalg_x1x.cpp
predict_linalg_${STATE_SIZE}x1x${INPUT_SIZE}.cpp)
get_filename_component(
NAME predict_linalg_${STATE_SIZE}x1x${INPUT_SIZE}.cpp NAME_WE)
add_executable(kalman_benchmark_${BACKEND}_${NAME}_driver
predict_linalg_${STATE_SIZE}x1x${INPUT_SIZE}.cpp)
target_include_directories(kalman_benchmark_${BACKEND}_${NAME}_driver
PRIVATE "include")
set_target_properties(kalman_benchmark_${BACKEND}_${NAME}_driver
PROPERTIES CXX_STANDARD 23)
set_target_properties(kalman_benchmark_${BACKEND}_${NAME}_driver
PROPERTIES CXX_EXTENSIONS OFF)
target_link_libraries(
kalman_benchmark_${BACKEND}_${NAME}_driver
PRIVATE benchmark::benchmark benchmark::benchmark_main kalman
kalman_linalg_${BACKEND})
add_test(kalman_benchmark_${BACKEND}_${NAME}
kalman_benchmark_${BACKEND}_${NAME}_driver
"--benchmark_out=${NAME}.json")
endforeach()
endforeach()
endforeach()
# foreach(BACKEND IN ITEMS "eigen") foreach(STATE_SIZE RANGE 1 2)
# foreach(OUTPUT_SIZE RANGE 1 2) configure_file(update_linalg_xx0.cpp
# update_linalg_${STATE_SIZE}x${OUTPUT_SIZE}x0.cpp) get_filename_component( NAME
# update_linalg_${STATE_SIZE}x${OUTPUT_SIZE}x0.cpp NAME_WE)
# add_executable(kalman_benchmark_${BACKEND}_${NAME}_driver
# update_linalg_${STATE_SIZE}x${OUTPUT_SIZE}x0.cpp)
# target_include_directories(kalman_benchmark_${BACKEND}_${NAME}_driver PRIVATE
# "include") set_target_properties(kalman_benchmark_${BACKEND}_${NAME}_driver
# PROPERTIES CXX_STANDARD 23)
# set_target_properties(kalman_benchmark_${BACKEND}_${NAME}_driver PROPERTIES
# CXX_EXTENSIONS OFF) target_link_libraries(
# kalman_benchmark_${BACKEND}_${NAME}_driver PRIVATE benchmark::benchmark
# benchmark::benchmark_main kalman kalman_linalg_${BACKEND})
# add_test(kalman_benchmark_${BACKEND}_${NAME}
# kalman_benchmark_${BACKEND}_${NAME}_driver "--benchmark_out=${NAME}.json")
# endforeach() foreach(INPUT_SIZE RANGE 1 2)
# configure_file(predict_linalg_x1x.cpp
# predict_linalg_${STATE_SIZE}x1x${INPUT_SIZE}.cpp) get_filename_component( NAME
# predict_linalg_${STATE_SIZE}x1x${INPUT_SIZE}.cpp NAME_WE)
# add_executable(kalman_benchmark_${BACKEND}_${NAME}_driver
# predict_linalg_${STATE_SIZE}x1x${INPUT_SIZE}.cpp)
# target_include_directories(kalman_benchmark_${BACKEND}_${NAME}_driver PRIVATE
# "include") set_target_properties(kalman_benchmark_${BACKEND}_${NAME}_driver
# PROPERTIES CXX_STANDARD 23)
# set_target_properties(kalman_benchmark_${BACKEND}_${NAME}_driver PROPERTIES
# CXX_EXTENSIONS OFF) target_link_libraries(
# kalman_benchmark_${BACKEND}_${NAME}_driver PRIVATE benchmark::benchmark
# benchmark::benchmark_main kalman kalman_linalg_${BACKEND})
# add_test(kalman_benchmark_${BACKEND}_${NAME}
# kalman_benchmark_${BACKEND}_${NAME}_driver "--benchmark_out=${NAME}.json")
# endforeach() endforeach() endforeach()
20 changes: 16 additions & 4 deletions benchmark/update_linalg_xx0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,25 @@ For more information, please refer to <https://unlicense.org> */
#include <cstring>
#include <random>

// template <typename Numerator, fcarouge::algebraic Denominator>
// constexpr auto fcarouge::operator/(const Numerator &lhs, const Denominator
// &rhs)
// -> fcarouge::quotient<Numerator, Denominator>
// requires fcarouge::eigen<Denominator>
// {
// return rhs.transpose()
// .fullPivHouseholderQr()
// .solve(lhs.transpose())
// .transpose();
// }

template <typename Numerator, fcarouge::algebraic Denominator>
constexpr auto fcarouge::operator/(const Numerator &lhs, const Denominator &rhs)
-> fcarouge::quotient<Numerator, Denominator> {
return rhs.transpose()
.fullPivHouseholderQr()
.solve(lhs.transpose())
.transpose();
assert(false);
static_cast<void>(lhs);
static_cast<void>(rhs);
return {};
}

namespace fcarouge::benchmark {
Expand Down
1 change: 1 addition & 0 deletions include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ install(
TARGETS kalman
EXPORT "kalman-target"
FILE_SET "kalman_headers")
# Redundant from cmake/install?
install(
EXPORT "kalman-target"
NAMESPACE "kalman::"
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 @@ -118,6 +118,9 @@ template <typename Matrix>
requires requires(Matrix value) { value.Zero(); }
inline const auto zero_v<Matrix>{Matrix::Zero()};

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

struct transpose final {
template <arithmetic Arithmetic>
[[nodiscard]] inline constexpr auto
Expand All @@ -130,6 +133,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 @@ -148,6 +156,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)
Loading

0 comments on commit 0286956

Please sign in to comment.