def is_positive_semidefinite_matrix(mat, rtol=RTOL_DEFAULT, atol=ATOL_DEFAULT):
if atol is None:<EOL><INDENT>atol = ATOL_DEFAULT<EOL><DEDENT>if rtol is None:<EOL><INDENT>rtol = RTOL_DEFAULT<EOL><DEDENT>if not is_hermitian_matrix(mat, rtol=rtol, atol=atol):<EOL><INDENT>return False<EOL><DEDENT>vals = np.linalg.eigvalsh(mat)<EOL>for v in vals:<EOL><INDENT>if v < -atol:<EOL><INDENT>return False<EOL><DEDENT><DEDENT>return True<EOL>
Test if a matrix is positive semidefinite