Skip to content

Commit

Permalink
gh-208: remove legacy random number generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Saransh-cpp committed Sep 18, 2024
1 parent a101ab4 commit 40f13c5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
5 changes: 3 additions & 2 deletions tests/core/test_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ def test_nnls():
from scipy.optimize import nnls as nnls_scipy
from glass.core.algorithm import nnls as nnls_glass

a = np.random.randn(100, 20)
b = np.random.randn(100)
rng = np.random.default_rng(seed=42)
a = rng.standard_normal((100, 20))
b = rng.standard_normal((100,))

x_glass = nnls_glass(a, b)
x_scipy, _ = nnls_scipy(a, b)
Expand Down
17 changes: 10 additions & 7 deletions tests/test_lensing.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ def test_deflect_many():
from glass.lensing import deflect

n = 1000
abs_alpha = np.random.uniform(0, 2 * np.pi, size=n)
arg_alpha = np.random.uniform(-np.pi, np.pi, size=n)
rng = np.random.default_rng(seed=42)
abs_alpha = rng.uniform(0, 2 * np.pi, size=n)
arg_alpha = rng.uniform(-np.pi, np.pi, size=n)

lon_ = np.degrees(np.random.uniform(-np.pi, np.pi, size=n))
lat_ = np.degrees(np.arcsin(np.random.uniform(-1, 1, size=n)))
lon_ = np.degrees(rng.uniform(-np.pi, np.pi, size=n))
lat_ = np.degrees(np.arcsin(rng.uniform(-1, 1, size=n)))

lon, lat = deflect(lon_, lat_, abs_alpha * np.exp(1j * arg_alpha))

Expand All @@ -101,7 +102,8 @@ def test_multi_plane_matrix(shells, cosmo):

convergence = MultiPlaneConvergence(cosmo)

deltas = np.random.rand(len(shells), 10)
rng = np.random.default_rng(seed=42)
deltas = rng.random((len(shells), 10))
kappas = []
for shell, delta in zip(shells, deltas):
convergence.add_window(delta, shell)
Expand All @@ -121,8 +123,9 @@ def test_multi_plane_weights(shells, cosmo):

convergence = MultiPlaneConvergence(cosmo)

deltas = np.random.rand(len(shells), 10)
weights = np.random.rand(len(shells), 3)
rng = np.random.default_rng(seed=42)
deltas = rng.random((len(shells), 10))
weights = rng.random((len(shells), 3))
kappa = 0
for shell, delta, weight in zip(shells, deltas, weights):
convergence.add_window(delta, shell)
Expand Down
5 changes: 3 additions & 2 deletions tests/test_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ def test_position_weights():

for bshape in None, (), (100,), (100, 1):
for cshape in (100,), (100, 50), (100, 3, 2):
counts = np.random.rand(*cshape)
bias = None if bshape is None else np.random.rand(*bshape)
rng = np.random.default_rng(seed=42)
counts = rng.random(cshape)
bias = None if bshape is None else rng.random(bshape)

weights = position_weights(counts, bias)

Expand Down

0 comments on commit 40f13c5

Please sign in to comment.