Coverage for gpaw/test/matrix/test_invcholesky.py: 96%

26 statements  

« prev     ^ index     » next       coverage.py v7.7.1, created at 2025-07-12 00:18 +0000

1import numpy as np 

2import pytest 

3from gpaw.core.matrix import Matrix 

4from gpaw.mpi import broadcast_exception, world 

5 

6 

7@pytest.mark.parametrize('dtype', [float, complex]) 

8@pytest.mark.skipif(world.size > 2, reason='size>2') 

9def test_invcholesky(dtype): 

10 S0 = Matrix(2, 2, dist=(world, 1, 1), dtype=dtype) 

11 S = S0.new(dist=(world, world.size, 1)) 

12 if world.rank == 0: 

13 if dtype == float: 

14 S0.data[:] = np.array([[1.0, 117], [0.1, 2.0]]) 

15 else: 

16 S0.data[:] = np.array([[1.0, 117], [0.1j, 2.0]]) 

17 S0.redist(S) 

18 L = S.copy() 

19 L.invcholesky() 

20 S.tril2full() 

21 if world.size == 1: 

22 print(L.data @ S.data @ L.data.T.conj()) 

23 else: 

24 print(world.rank, L.data) 

25 A = L.multiply(S, opa='N').multiply(L, opb='C') 

26 print(A.data) 

27 A.redist(S0) 

28 with broadcast_exception(world): 

29 if world.rank == 0: 

30 assert abs(S0.data - np.eye(2)).max() < 1e-14