Coverage for gpaw/test/matrix/test_inv.py: 93%
28 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-09 00:21 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-09 00:21 +0000
1import numpy as np
2import pytest
3from gpaw.core.matrix import Matrix
4from gpaw.mpi import broadcast_exception, world
7@pytest.mark.parametrize('dtype', [float, complex])
8def test_inv(dtype):
9 if world.size > 1 and dtype == float:
10 pytest.skip('Not implemented')
12 N = 15
13 S0 = Matrix(N, N,
14 dist=(world, 1, 1),
15 dtype=dtype)
17 if world.rank == 0:
18 S0.data[:] = np.diag(np.arange(1, N + 1))
19 if dtype == float:
20 S0.data[-1, 0] = 0.1
21 else:
22 S0.data[-1, 0] = 0.1j
24 S = S0.new(dist=(world, world.size, 1, 2))
25 S0.redist(S)
27 iS = S.copy()
28 iS.inv()
30 S.tril2full()
31 iS.tril2full()
33 A = S.multiply(iS)
34 A.redist(S0)
36 with broadcast_exception(world):
37 if world.rank == 0:
38 assert abs(S0.data - np.eye(N)).max() < 1e-14
41if __name__ == '__main__':
42 test_inv(complex)