From 2b524865f32210459e25bba3d5fcb416ac39a274 Mon Sep 17 00:00:00 2001 From: atrayees <121290945+atrayees@users.noreply.github.com> Date: Fri, 14 Jun 2024 10:16:49 +0530 Subject: [PATCH] reuse function isPositiveSemidefinite() --- examples/correlation_matrices/sampler.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/examples/correlation_matrices/sampler.cpp b/examples/correlation_matrices/sampler.cpp index caa414090..c8e63ac55 100644 --- a/examples/correlation_matrices/sampler.cpp +++ b/examples/correlation_matrices/sampler.cpp @@ -17,6 +17,7 @@ #include "convex_bodies/spectrahedra/spectrahedron.h" #include "random_walks/random_walks.hpp" #include "sampling/sample_correlation_matrices.hpp" +#include "matrix_operations/EigenvaluesProblems.h" typedef double NT; typedef Eigen::Matrix MT; @@ -99,16 +100,16 @@ bool is_correlation_matrix(const MT& matrix, const double tol = 1e-8){ } } - //check if the matrix is positive definite - Eigen::SelfAdjointEigenSolver eigen_solver(matrix); + //check if the matrix is positive semidefinite + using NT = double; + using MatrixType = Eigen::Matrix; + EigenvaluesProblems> solver; - if(eigen_solver.info() != Eigen::Success) + if(solver.isPositiveSemidefinite(matrix)) { - return false; + return true; } - - //the matrix is positive definite if all eigenvalues are positive - return eigen_solver.eigenvalues().minCoeff() > -tol; + return false; } template