From a2a799b591f3fb35f3def3d09f8d3fd60aa8a9d5 Mon Sep 17 00:00:00 2001 From: Fabian Joswig Date: Fri, 10 Dec 2021 14:39:14 +0000 Subject: [PATCH] feat: linalg.det added, test added --- pyerrors/linalg.py | 7 ++++++- tests/linalg_test.py | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pyerrors/linalg.py b/pyerrors/linalg.py index afdcb18a..3b1950eb 100644 --- a/pyerrors/linalg.py +++ b/pyerrors/linalg.py @@ -203,7 +203,12 @@ def cholesky(x): return _mat_mat_op(anp.linalg.cholesky, x) -def scalar_mat_op(op, obs, **kwargs): +def det(x): + """Determinant of Obs valued matrices.""" + return _scalar_mat_op(anp.linalg.det, x) + + +def _scalar_mat_op(op, obs, **kwargs): """Computes the matrix to scalar operation op to a given matrix of Obs.""" def _mat(x, **kwargs): dim = int(np.sqrt(len(x))) diff --git a/tests/linalg_test.py b/tests/linalg_test.py index bc45a8f0..f446d972 100644 --- a/tests/linalg_test.py +++ b/tests/linalg_test.py @@ -311,6 +311,9 @@ def test_matrix_functions(): for (i, j), entry in np.ndenumerate(diff): assert entry.is_zero() + # Check determinant + assert pe.linalg.det(np.diag(np.diag(matrix))) == np.prod(np.diag(matrix)) + def test_complex_matrix_operations(): dimension = 4