# Fast way of checking whether a matrix is positive definite without Cholesky decomposition

I would like to check whether a matrix $$A$$ is positive definite. Previous answers to this question have pointed to the Cholesky decomposition. However, since my framework of choice is Tensorflow, I cannot catch and handle the exception thrown when the decomposition discovers that the matrix is not positive definite, so I need another way.

Another approach I have seen is to compute the eigenvalues, and check whether any of them are negative. This works, but it is slow. I have also heard the suggestion to compute the smallest eigenvalue. This makes sense to me -- if it is negative, we know the matrix is not positive definite -- but I am unsure how to do this efficiently. I would be grateful for some pointers!

• – Will Jagy Oct 17 '18 at 2:25

Use the Cholesky Decomp, I don't understand why you can't handle an exception. This is from StackOverflow.

import numpy as np

def is_pd(K):
try:
np.linalg.cholesky(K)
return 1
except np.linalg.linalg.LinAlgError as err:
if 'Matrix is not positive definite' in err.message:
return 0
else:
raise

• I am afraid I am using tensorflow, not numpy. Tensorflow's graph-based execution means errors cannot be handled dynamically. See: github.com/GPflow/GPflow/issues/553 . Also: github.com/tensorflow/tensorflow/issues/10332 – noctilux Oct 17 '18 at 3:42
• this is clearly an issue for stack overflow. the best choice is still cholesky because it is more computationally expensive to compute eigenvalues. – Shogun Oct 17 '18 at 3:44
• I don't know much of anything about tensorflow and why it can't handle simple errors.. – Shogun Oct 17 '18 at 3:46
• or at best code review, not mathstack it isn't a question about math. – Shogun Oct 17 '18 at 3:53
• Thank you for your comment, but I do think it is a math question. If there is no fast / convenient alternative to check positive definiteness, that's fine, but I would like to know if there is, hence this question. – noctilux Oct 17 '18 at 4:00