Skip to content

Commit 4552d80

Browse files
committed
add unittest to check model.is_valid
1 parent f0134ab commit 4552d80

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/src/dense_qp_wrapper.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7564,3 +7564,27 @@ TEST_CASE(
75647564
minimal_eigenvalue) <= tol);
75657565
}
75667566
}
7567+
7568+
DOCTEST_TEST_CASE("check that model.is_valid function for symmetric matrices "
7569+
"works for epsilon precision")
7570+
{
7571+
Eigen::Matrix<T, 3, 3> matrix = Eigen::Matrix<T, 3, 3>::Random();
7572+
Eigen::Matrix<T, 3, 3> symmetric_mat = matrix + matrix.transpose();
7573+
7574+
symmetric_mat(0, 1) =
7575+
symmetric_mat(1, 0) + std::numeric_limits<double>::epsilon();
7576+
7577+
// compare the two checks for symmetry with and without tolerance
7578+
bool is_symmetric_without_tolerance =
7579+
symmetric_mat.isApprox(symmetric_mat.transpose(), 0.0);
7580+
bool is_symmetric_with_tolerance = symmetric_mat.isApprox(
7581+
symmetric_mat.transpose(),
7582+
std::numeric_limits<typename decltype(symmetric_mat)::Scalar>::epsilon());
7583+
DOCTEST_CHECK(is_symmetric_without_tolerance == false);
7584+
DOCTEST_CHECK(is_symmetric_with_tolerance == true);
7585+
7586+
// initialize a model with a symmetric matrix as Hessian, this runs
7587+
// model.is_valid() that performs the check above
7588+
proxqp::dense::QP<T> qp(3, 0, 0);
7589+
qp.init(symmetric_mat, nullopt, nullopt, nullopt, nullopt, nullopt, nullopt);
7590+
}

0 commit comments

Comments
 (0)