Coverage for gpaw/test/matrix/test_eigh.py: 22%
27 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-19 00:19 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-19 00:19 +0000
1import pytest
2import numpy as np
3from gpaw.core.matrix import Matrix
4from gpaw.mpi import world
7@pytest.mark.skipif(world.size != 4, reason='size!=4')
8def test_matrix_eigh(rng):
9 """Test eigenvalues for different BLACS layouts.
11 See also #269.
12 """
13 N = 6
14 x = 0.01
16 A0 = Matrix(N, N, dist=(world, 1, 1), dtype=complex)
18 if world.rank == 0:
19 A0.data[:] = np.diag(np.arange(N) + 1)
20 A0.data += rng.uniform(-x, x, (N, N))
21 A0.data += A0.data.conj().T
22 B = Matrix(N, N, data=A0.data.copy())
23 eigs0 = B.eigh(cc=True)
24 else:
25 eigs0 = np.empty(N)
27 world.broadcast(eigs0, 0)
29 A = Matrix(N, N, dist=(world, 2, 2, 2), dtype=complex)
30 B0 = Matrix(N, N, dist=(world, 1, 1), dtype=complex)
32 for dist in [(1, 2), (2, 1), (2, 2)]:
33 A0.redist(A)
34 eigs = A.eigh(cc=True, scalapack=(world, *dist, 2))
35 assert eigs == pytest.approx(eigs0, abs=1e-13)
36 print(world.rank, eigs)
37 A.redist(B0)
38 if world.rank == -1:
39 assert abs(B0.data) == pytest.approx(abs(B.data), abs=1e-13)