Coverage for ase / _4 / symopt / test_cholesky_deriv.py: 100.00%
20 statements
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-21 15:52 +0000
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-21 15:52 +0000
1import numpy as np
2import pytest
4from ase._4.symopt.relax import chol_derivative
6pytestmark = pytest.mark.calculator_lite
9def numerical_chol_derivative(A, dA, eps=1e-10):
10 dA = (dA + dA.T) / 2
11 L = np.linalg.cholesky(A - eps * dA)
12 Lp = np.linalg.cholesky(A + eps * dA)
13 return (Lp - L) / (2 * eps)
16def test_chol_derivative():
17 for i in range(10):
18 # Create a random positive definite matrix
19 A = np.random.rand(3, 3)
20 A = A @ A.T
22 # Create a random perturbation
23 dA = np.random.rand(3, 3)
24 dA = dA - dA.T
25 numdL = numerical_chol_derivative(A, dA)
26 print('numdL', numdL)
27 analdL = chol_derivative(A, dA)
28 print('analdL', analdL)
30 assert np.allclose(numdL, analdL, atol=1e-4)