Coverage for gpaw/test/linalg/test_zher.py: 100%
31 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
2from gpaw.response.integrators import czher
3import numpy as np
4from time import time
7@pytest.mark.ci
8def test_linalg_zher(rng):
9 alpha = 0.5
10 x = rng.random(3) + 1j * rng.random(3)
11 a = rng.random(9).reshape(3, 3) + rng.random(9).reshape(3, 3) * 1j
13 # make a hermitian
14 for i in range(3):
15 for j in range(3):
16 a[i, j] = a[j, i].conj()
17 a[i, i] = np.real(a[i, i])
19 b = alpha * np.outer(x.conj(), x) + a
20 czher(alpha, x, a)
22 for i in range(3):
23 for j in range(i, 3):
24 a[j, i] = a[i, j].conj()
26 assert np.abs(b - a).sum() < 1e-14
28 # testing speed
29 t_czher = 0
30 t_axpy = 0
32 for i in np.arange(1000):
33 t0 = time()
34 czher(alpha, x, a)
35 t_czher += time() - t0
37 t0 = time()
38 xx = np.outer(x.conj(), x)
39 a += alpha * xx
40 t_axpy += time() - t0
42 print('t_czher:', t_czher)
43 print('t_axpy:', t_axpy)