Skip to content

Commit 4e4e6da

Browse files
TEST: redesign test_randn_normal_distribution (#372)
1 parent 5640a99 commit 4e4e6da

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

tests/skipped_tests.tbl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ tests/test_linalg.py::test_norm3[(1, 2)-2-[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]]
125125
tests/test_linalg.py::test_norm3[(1, 2)-2-[[[1, 0], [3, 0]], [[5, 0], [7, 0]]]]
126126
tests/test_linalg.py::test_norm3[(1, 2)-3-[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]]
127127
tests/test_linalg.py::test_norm3[(1, 2)-3-[[[1, 0], [3, 0]], [[5, 0], [7, 0]]]]
128-
tests/test_random.py::test_randn_normal_distribution
129128
tests/test_random.py::test_rayleigh_check_moments
130129
tests/test_random.py::test_gumbel_check_moments
131130
tests/third_party/cupy/binary_tests/test_elementwise.py::TestElementwise::test_bitwise_and

tests/skipped_tests_gpu.tbl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ tests/test_random.py::test_multivariate_normal_invalid_args
154154
tests/test_random.py::test_multivariate_normal_output_shape_check
155155
tests/test_random.py::test_multivariate_normal_seed
156156
tests/test_random.py::test_negative_binomial_seed
157-
tests/test_random.py::test_randn_normal_distribution
158157
tests/test_random.py::test_rayleigh_check_moments
159158
tests/test_random.py::test_standard_gamma_check_extreme_value
160159
tests/test_random.py::test_standard_gamma_check_moments

tests/test_random.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import dpnp.random
44
import numpy
5-
# from scipy import stats
65
from numpy.testing import assert_allclose
76
import math
87

@@ -800,24 +799,26 @@ def test_poisson_check_extreme_value():
800799

801800

802801
def test_randn_normal_distribution():
803-
""" Check if the sample obtained from the dpnp.random.randn differs from
804-
the normal distribution.
805-
Using ``scipy.stats.normaltest``.
802+
"""
803+
Check the moments of the normal distribution sample obtained
804+
from ``dpnp.random.randn``.
806805
807-
It is based on D’Agostino and Pearson’s test that combines skew
808-
and kurtosis to produce an omnibus test of normality,
809-
see: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.normaltest.html
810806
"""
811-
pts = 1000
807+
808+
seed = 28041995
809+
pts = 10**5
812810
alpha = 0.05
813-
dpnp.random.seed(28041990)
814-
x = dpnp.random.randn(pts)
815-
_, p = stats.normaltest(x)
816-
# null hypothesis: x comes from a normal distribution.
817-
# The p-value is interpreted against an alpha of 5% and finds that the test
818-
# dataset does not significantly deviate from normal.
819-
# If p > alpha, the null hypothesis cannot be rejected.
820-
assert p > alpha
811+
812+
expected_mean = 0.0
813+
expected_var = 1.0
814+
815+
dpnp.random.seed(seed)
816+
res = dpnp.random.randn(pts)
817+
818+
var = numpy.var(res)
819+
mean = numpy.mean(res)
820+
assert math.isclose(var, expected_var, abs_tol=0.03)
821+
assert math.isclose(mean, expected_mean, abs_tol=0.03)
821822

822823

823824
def test_rayleigh_seed():

0 commit comments

Comments
 (0)