-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: add compile time testing for Distribution types.
- Loading branch information
Showing
7 changed files
with
151 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#pragma once | ||
|
||
#include <Eigen/Core> | ||
|
||
#include <concepts> | ||
|
||
|
||
namespace DO::Sara { | ||
|
||
|
||
template <typename T> | ||
concept MatrixConcept = requires(T) | ||
{ | ||
// clang-format off | ||
{ T{}.rows() }; | ||
{ T{}.cols() }; | ||
{ T{}(int{}, int{}) }; | ||
{ T{}.transpose() }; | ||
// clang-format on | ||
}; | ||
|
||
template <typename T> | ||
concept VectorConcept = MatrixConcept<T> && requires(T) | ||
{ | ||
T::ColsAtCompileTime == 1; | ||
// clang-format off | ||
{ T{}(int{}) }; | ||
// clang-format on | ||
}; | ||
|
||
template <typename T> | ||
concept CompileTimeSizedMatrixConcept = MatrixConcept<T> && requires(T) | ||
{ | ||
std::same_as<T, Eigen::Matrix<typename T::Scalar, T::RowsAtCompileTime, | ||
T::ColsAtCompileTime>>; | ||
// clang-format off | ||
{ T::RowsAtCompileTime }; | ||
{ T::ColsAtCompileTime }; | ||
// clang-format on | ||
}; | ||
|
||
template <typename T> | ||
concept CompileTimeSquareMatrixConcept = | ||
CompileTimeSizedMatrixConcept<T> && requires | ||
{ | ||
T::RowsAtCompileTime == T::ColsAtCompileTime; | ||
}; | ||
|
||
} // namespace DO::Sara |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
file(GLOB test_SOURCE_FILES FILES test_*.cpp) | ||
|
||
foreach (file ${test_SOURCE_FILES}) | ||
get_filename_component(filename "${file}" NAME_WE) | ||
sara_add_test( | ||
NAME ${filename} | ||
SOURCES ${file} | ||
DEPENDENCIES DO::Sara::Core | ||
FOLDER KalmanFilter) | ||
endforeach () |
44 changes: 44 additions & 0 deletions
44
cpp/test/Sara/KalmanFilter/test_kalman_filter_concepts.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// ========================================================================== // | ||
// This file is part of Sara, a basic set of libraries in C++ for computer | ||
// vision. | ||
// | ||
// Copyright (C) 2023-present David Ok <[email protected]> | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// you can obtain one at http://mozilla.org/MPL/2.0/. | ||
// ========================================================================== // | ||
|
||
#define BOOST_TEST_MODULE "Kalman Filter/Concepts" | ||
|
||
#include <DO/Sara/KalmanFilter/DistributionConcepts.hpp> | ||
#include <DO/Sara/KalmanFilter/MatrixConcepts.hpp> | ||
#include <DO/Sara/MultipleObjectTracking/BaseDefinitions.hpp> | ||
|
||
#include <boost/test/unit_test.hpp> | ||
|
||
|
||
namespace sara = DO::Sara; | ||
namespace mot = DO::Sara::MultipleObjectTracking; | ||
|
||
|
||
BOOST_AUTO_TEST_SUITE(TestKalmanFilter) | ||
|
||
BOOST_AUTO_TEST_CASE(test_matrix_concepts) | ||
{ | ||
[[maybe_unused]] const sara::VectorConcept auto x = Eigen::Vector2d{}; | ||
[[maybe_unused]] const sara::CompileTimeSquareMatrixConcept auto m = | ||
Eigen::Matrix4f{}; | ||
} | ||
|
||
BOOST_AUTO_TEST_CASE(test_distribution_concepts) | ||
{ | ||
[[maybe_unused]] const sara::GaussianDistribution auto x = | ||
mot::StateDistribution<double>{}; | ||
|
||
[[maybe_unused]] const sara::GaussianDistribution auto z = | ||
mot::ObservationDistribution<double>{}; | ||
} | ||
|
||
|
||
BOOST_AUTO_TEST_SUITE_END() |