Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added check for matrix positive definiteness #574

Merged
merged 1 commit into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions burnman/utils/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,3 +553,16 @@ def generate_complete_basis(incomplete_basis, array):
)

return complete_basis.round(decimals=12) + 0.0


def is_positive_definite(matrix):
"""
Checks if a matrix is positive definite
:param matrix: Input matrix
:type matrix: 2D numpy array
:return: Whether or not the matrix is positive definite
:rtype: bool
"""
return np.all(np.linalg.eigvals(matrix) > 0)
5 changes: 5 additions & 0 deletions tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from burnman.utils.math import smooth_array
from burnman.utils.math import interp_smoothed_array_and_derivatives
from burnman.utils.math import _pad_ndarray_inverse_mirror
from burnman.utils.math import is_positive_definite


class test_tools(BurnManTest):
Expand Down Expand Up @@ -200,6 +201,10 @@ def test_reactions_from_formulae(self):
)
self.assertTrue(R[0] == "2 fa = 2 fper + 1 fs")

def test_positive_definite(self):
arr = np.array([[2.0, 0.0], [0.0, 1.0]])
self.assertTrue(is_positive_definite(arr))


if __name__ == "__main__":
unittest.main()
Loading