Coverage for gpaw/test/new/test_pwlfc_expand.py: 100%
43 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-20 00:19 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-20 00:19 +0000
1import numpy as np
2import pytest
4seed = 42
7def test_pwlfc_expand():
8 from gpaw.new.c import pwlfc_expand as c_call
9 from gpaw.purepython import pwlfc_expand as pp_call
10 assert pp_call is not c_call
12 cc = False
13 dtype = np.complex128
15 rng = np.random.RandomState(seed)
16 GN = 3000
17 aN = 5
18 sN = 7
19 LN = (sN + 1)**2
21 f_Gs = rng.randn(GN, sN)
22 Gk_Gv = rng.randn(GN, 3)
23 pos_av = rng.randn(aN, 3)
24 eikR_a = rng.randn(aN) \
25 + 1j * rng.randn(aN)
26 Y_GL = rng.randn(GN, LN)
28 gN = GN if np.issubdtype(dtype, np.complexfloating) else 2 * GN
29 l_s = np.arange(sN, dtype=np.int32)
30 a_J = []
31 s_J = []
33 for a in range(aN):
34 for s in range(sN):
35 a_J.append(a)
36 s_J.append(s)
37 JN = len(a_J)
38 a_J = np.asarray(a_J, dtype=np.int32)
39 s_J = np.asarray(s_J, dtype=np.int32)
41 I_J = np.zeros(JN, dtype=np.int32)
42 I1 = 0
43 for J, (a, s) in enumerate(zip(a_J, s_J)):
44 l = l_s[s]
45 I2 = I1 + 2 * l + 1
46 I_J[J] = I1
47 I1 = I2
48 IN = I2
50 f_c_GI = np.zeros((gN, IN), dtype=dtype)
51 f_pp_GI = np.zeros((gN, IN), dtype=dtype)
53 c_call(f_Gs, Gk_Gv, pos_av,
54 eikR_a, Y_GL,
55 l_s, a_J, s_J,
56 cc, f_c_GI)
57 pp_call(f_Gs, Gk_Gv, pos_av,
58 eikR_a, Y_GL,
59 l_s, a_J, s_J,
60 cc, f_pp_GI)
62 assert f_c_GI == pytest.approx(f_pp_GI, abs=1e-6)