File indexing completed on 2025-08-06 08:11:31
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/data/test_case.hpp>
0010 #include <boost/test/unit_test.hpp>
0011
0012 #include "Acts/Utilities/AlgebraHelpers.hpp"
0013 #include "Acts/Utilities/Logger.hpp"
0014
0015 #include <Eigen/Dense>
0016
0017 Acts::Logging::Level logLevel = Acts::Logging::VERBOSE;
0018
0019 namespace Acts {
0020 namespace Test {
0021
0022 BOOST_AUTO_TEST_SUITE(AlgebraHelpers)
0023
0024 ACTS_LOCAL_LOGGER(Acts::getDefaultLogger("SafeInverse", logLevel))
0025
0026 BOOST_AUTO_TEST_CASE(SafeInverseSmallMatrix) {
0027 Eigen::Matrix<double, 2, 2> m;
0028 m << 1, 2, 3, 4;
0029
0030 Eigen::Matrix<double, 2, 2> mInvRef;
0031 mInvRef << -2, 1, 1.5, -0.5;
0032
0033 auto mInv = Acts::safeInverse(m);
0034
0035 BOOST_CHECK(mInv);
0036 BOOST_CHECK_EQUAL(*mInv, mInvRef);
0037
0038 Eigen::Matrix<int, 2, 2> identityInt;
0039 identityInt << 1, 0, 0, 1;
0040 auto identityIntInv = Acts::safeInverse(identityInt);
0041
0042 BOOST_CHECK(identityIntInv);
0043 BOOST_CHECK_EQUAL(*identityIntInv, identityInt);
0044 }
0045
0046 BOOST_AUTO_TEST_CASE(safeInverseLargeMatrix) {
0047 const Eigen::Matrix<double, 5, 5> identity{Eigen::MatrixXd::Identity(5, 5)};
0048 auto identityInv = Acts::safeInverse(identity);
0049
0050 BOOST_CHECK(identityInv);
0051 BOOST_CHECK_EQUAL(*identityInv, identity);
0052 }
0053
0054 BOOST_AUTO_TEST_CASE(SafeInverseBadSmallMatrix) {
0055 Eigen::Matrix<double, 2, 2> m;
0056 m << 1, 1, 2, 2;
0057
0058 auto mInv = Acts::safeInverse(m);
0059
0060 BOOST_CHECK(!mInv);
0061 }
0062
0063 BOOST_AUTO_TEST_CASE(safeInverseBadLargeMatrix) {
0064 const Eigen::Matrix<double, 5, 5> m{Eigen::MatrixXd::Zero(5, 5)};
0065 auto mInv = Acts::safeInverse(m);
0066
0067 BOOST_CHECK(!mInv);
0068 }
0069
0070 BOOST_AUTO_TEST_CASE(SafeInverseFPESmallMatrix) {
0071 Eigen::Matrix<double, 4, 4> m = Eigen::MatrixXd::Identity(4, 4) * SIZE_MAX;
0072 m(1, 1) = 1;
0073
0074 auto mInv = Acts::safeInverse(m);
0075 auto mInvInv = Acts::safeInverse(*mInv);
0076
0077 BOOST_CHECK(mInv);
0078 BOOST_CHECK(!mInvInv);
0079
0080 ACTS_VERBOSE("Test: SafeInverseFPESmallMatrix"
0081 << "\n"
0082 << "m:\n"
0083 << m << "\n"
0084 << "mInv:\n"
0085 << *mInv << "\n"
0086 << "mInvInv [garbage]:\n"
0087 << *mInvInv);
0088 }
0089
0090 BOOST_AUTO_TEST_CASE(SafeInverseFPELargeMatrix) {
0091 Eigen::Matrix<double, 5, 5> m = Eigen::MatrixXd::Identity(5, 5) * SIZE_MAX;
0092 m(1, 1) = 1;
0093
0094 auto mInv = Acts::safeInverse(m);
0095
0096 BOOST_CHECK(!mInv);
0097
0098 ACTS_VERBOSE("Test: SafeInverseFPELargeMatrix"
0099 << "\n"
0100 << "m:\n"
0101 << m << "\n"
0102 << "mInv [garbage]:\n"
0103 << *mInv);
0104 }
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121 BOOST_AUTO_TEST_SUITE_END()
0122
0123 }
0124 }