|
2 | 2 |
|
3 | 3 | import dpnp.random
|
4 | 4 | import numpy
|
5 |
| - |
| 5 | +# from scipy import stats |
| 6 | +from numpy.testing import assert_allclose |
6 | 7 |
|
7 | 8 | @pytest.mark.parametrize("func",
|
8 | 9 | [dpnp.random.rand,
|
@@ -49,3 +50,48 @@ def test_random_check_otput(func):
|
49 | 50 | for i in range(res.size):
|
50 | 51 | assert res[i] >= 0.0
|
51 | 52 | assert res[i] < 1.0
|
| 53 | + |
| 54 | + |
| 55 | +def test_randn_normal_distribution(): |
| 56 | + """ Check if the sample obtained from the dpnp.random.randn differs from |
| 57 | + the normal distribution. |
| 58 | + Using ``scipy.stats.normaltest``. |
| 59 | +
|
| 60 | + It is based on D’Agostino and Pearson’s test that combines skew |
| 61 | + and kurtosis to produce an omnibus test of normality, |
| 62 | + see: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.normaltest.html |
| 63 | + """ |
| 64 | + pts = 1000 |
| 65 | + alpha = 0.05 |
| 66 | + dpnp.random.seed(28041990) |
| 67 | + x = dpnp.random.randn(pts) |
| 68 | + _, p = stats.normaltest(x) |
| 69 | + # null hypothesis: x comes from a normal distribution. |
| 70 | + # The p-value is interpreted against an alpha of 5% and finds that the test |
| 71 | + # dataset does not significantly deviate from normal. |
| 72 | + # If p > alpha, the null hypothesis cannot be rejected. |
| 73 | + assert p > alpha |
| 74 | + |
| 75 | + |
| 76 | +@pytest.mark.parametrize("func", |
| 77 | + [dpnp.random.random, |
| 78 | + dpnp.random.random_sample, |
| 79 | + dpnp.random.randf, |
| 80 | + dpnp.random.sample, |
| 81 | + dpnp.random.rand], |
| 82 | + ids=['random', 'random_sample', |
| 83 | + 'randf', 'sample', |
| 84 | + 'rand']) |
| 85 | +def test_radnom_seed(func): |
| 86 | + seed = 28041990 |
| 87 | + size = 100 |
| 88 | + shape = (100, 1) |
| 89 | + if func in [dpnp.random.rand, dpnp.random.randn]: |
| 90 | + args = size |
| 91 | + else: |
| 92 | + args = shape |
| 93 | + dpnp.random.seed(seed) |
| 94 | + a1 = func(args) |
| 95 | + dpnp.random.seed(seed) |
| 96 | + a2 = func(args) |
| 97 | + assert_allclose(a1, a2, rtol=1e-07, atol=0) |
0 commit comments