Skip to content

Commit 4ac3641

Browse files
committed
tests for glass.grf._solver
1 parent 42a0430 commit 4ac3641

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

tests/grf/test_solver.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import numpy as np
2+
import numpy.testing as npt
3+
4+
import glass.grf
5+
6+
7+
def test_lognormal(rng):
8+
t1 = glass.grf.Lognormal()
9+
t2 = glass.grf.Lognormal()
10+
11+
gl0 = rng.random()
12+
13+
lmax = 100
14+
ell = np.arange(lmax + 1)
15+
cl = 1e-2 / (2 * ell + 1) ** 2
16+
17+
cltol = 1e-7
18+
19+
gl, cl_, info = glass.grf.solve(cl, t1, t2, monopole=gl0, cltol=cltol)
20+
21+
assert info > 0
22+
23+
npt.assert_allclose(cl_[1 : cl.size], cl[1:], atol=0.0, rtol=cltol)
24+
25+
gl_ = glass.grf.compute(cl_, t1, t2)
26+
27+
assert gl[0] == gl0
28+
npt.assert_allclose(gl_[1 : gl.size], gl[1:])
29+
30+
31+
def test_monopole(rng):
32+
t = glass.grf.Normal()
33+
x = rng.random(100)
34+
35+
y, x_, _ = glass.grf.solve(x, t, monopole=None)
36+
37+
npt.assert_allclose(y, x)
38+
npt.assert_allclose(x_, x)
39+
40+
y, x_, _ = glass.grf.solve(x, t, monopole=0.0)
41+
42+
assert y[0] == 0.0
43+
44+
npt.assert_allclose(y[1:], x[1:])
45+
npt.assert_allclose(x_[1:], x[1:])
46+
47+
y, x_, _ = glass.grf.solve(x, t, monopole=1.0)
48+
49+
assert y[0] == 1.0
50+
51+
npt.assert_allclose(y[1:], x[1:])
52+
npt.assert_allclose(x_[1:], x[1:])

0 commit comments

Comments
 (0)