Coverage for gpaw/test/eigen/test_cg2.py: 100%

19 statements  

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

1import numpy as np 

2from gpaw.utilities.cg import CG 

3 

4 

5def test_eigen_cg2(): 

6 def A(x, b): 

7 b[:] = np.reshape(np.dot(np.reshape(x, (2, 4)), 

8 np.array([[1.0, 0.1, 0.0, 0.0], 

9 [0.1, 1.1, 0.1, 0.1], 

10 [0.0, 0.1, 0.8, 0.1], 

11 [0.0, 0.1, 0.1, 0.9]])), 

12 (2, 2, 1, 2)) 

13 A.sum = lambda x: x 

14 b = np.array([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0]]) 

15 b.shape = (2, 2, 1, 2) 

16 x = b.copy() 

17 niter, error = CG(A, x, b, verbose=1) 

18 assert niter < 5 

19 

20 def A(x, b): 

21 b[:] = np.reshape(np.dot(np.reshape(x, (2, 4)), 

22 np.array([[1.0, 0.1, 0.0, 0.0], 

23 [0.1, 1.1, 0.1, 0.1], 

24 [0.0, 0.1, 0.8, 0.1], 

25 [0.0, 0.1, 0.1, 0.9]])), 

26 (2, 2, 1, 2)) 

27 A.sum = lambda x: x 

28 

29 b = np.array([[1.0, 0.1j, 0.01 + 0.1j, 0.0], [0.0, 1.0, 0.0, 0.0]]) 

30 b.shape = (2, 2, 1, 2) 

31 x = b.copy() 

32 niter, error = CG(A, x, b, verbose=1) 

33 assert niter < 5