Skip to content

Commit 276e6aa

Browse files
committed
test: cover per-element scale and size=None shape mismatch for array paths
1 parent 41f385f commit 276e6aa

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

‎mkl_random/tests/test_random.py‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,31 @@ def test_one_param_array_matches_scalar(name, draw, p):
14521452
)
14531453

14541454

1455+
@pytest.mark.parametrize(
1456+
"name,draw,p",
1457+
[
1458+
("exponential", lambda r, a, s: r.exponential(a, s), 3.0),
1459+
("rayleigh", lambda r, a, s: r.rayleigh(a, s), 3.0),
1460+
],
1461+
ids=["exponential", "rayleigh"],
1462+
)
1463+
@pytest.mark.parametrize("size", [None, (3, 4)])
1464+
def test_one_param_array_applies_per_element(name, draw, p, size):
1465+
scale = np.linspace(p, p * 4.0, 4)
1466+
shape = scale.shape if size is None else size
1467+
reference = rnd.MKLRandomState(99)
1468+
expected = scale * draw(reference, 1.0, shape)
1469+
out = draw(rnd.MKLRandomState(99), scale, size)
1470+
assert out.shape == shape
1471+
np.testing.assert_allclose(
1472+
out,
1473+
expected,
1474+
rtol=1e-12,
1475+
atol=1e-12,
1476+
err_msg=f"{name}: per-element parameters are not applied correctly",
1477+
)
1478+
1479+
14551480
@pytest.mark.parametrize(
14561481
"loc_shape,scale_shape,size,expected",
14571482
[
@@ -1476,6 +1501,19 @@ def test_two_param_array_size_incompatible():
14761501
rnd.MKLRandomState(5).normal(np.zeros(5), np.ones(5), 3)
14771502

14781503

1504+
@pytest.mark.parametrize(
1505+
"name", ["normal", "uniform", "laplace", "gumbel", "logistic", "lognormal"]
1506+
)
1507+
def test_two_param_array_no_size_incompatible_shapes(name):
1508+
state = rnd.MKLRandomState(5)
1509+
reference = rnd.MKLRandomState(5)
1510+
with pytest.raises(ValueError):
1511+
getattr(state, name)(np.zeros(5), np.ones(3), None)
1512+
np.testing.assert_array_equal(
1513+
state.random_sample(32), reference.random_sample(32)
1514+
)
1515+
1516+
14791517
@pytest.mark.parametrize(
14801518
"name",
14811519
[

0 commit comments

Comments
 (0)