Skip to content

tests: more tests for random funcs #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tests/skipped_tests.tbl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ tests/test_random.py::test_random_check_otput[random_sample]
tests/test_random.py::test_random_check_otput[randf]
tests/test_random.py::test_random_check_otput[sample]
tests/test_random.py::test_random_check_otput[rand]
tests/test_random.py::test_randn_normal_distribution
tests/test_random.py::test_radnom_seed[random]
tests/test_random.py::test_radnom_seed[random_sample]
tests/test_random.py::test_radnom_seed[randf]
tests/test_random.py::test_radnom_seed[sample]
tests/test_random.py::test_radnom_seed[rand]
tests/third_party/cupy/binary_tests/test_elementwise.py::TestElementwise::test_bitwise_and
tests/third_party/cupy/binary_tests/test_elementwise.py::TestElementwise::test_bitwise_or
tests/third_party/cupy/binary_tests/test_elementwise.py::TestElementwise::test_bitwise_xor
Expand Down
48 changes: 47 additions & 1 deletion tests/test_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import dpnp.random
import numpy

# from scipy import stats
from numpy.testing import assert_allclose

@pytest.mark.parametrize("func",
[dpnp.random.rand,
Expand Down Expand Up @@ -49,3 +50,48 @@ def test_random_check_otput(func):
for i in range(res.size):
assert res[i] >= 0.0
assert res[i] < 1.0


def test_randn_normal_distribution():
""" Check if the sample obtained from the dpnp.random.randn differs from
the normal distribution.
Using ``scipy.stats.normaltest``.

It is based on D’Agostino and Pearson’s test that combines skew
and kurtosis to produce an omnibus test of normality,
see: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.normaltest.html
"""
pts = 1000
alpha = 0.05
dpnp.random.seed(28041990)
x = dpnp.random.randn(pts)
_, p = stats.normaltest(x)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How it is works is stats commented out above?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comments

# null hypothesis: x comes from a normal distribution.
# The p-value is interpreted against an alpha of 5% and finds that the test
# dataset does not significantly deviate from normal.
# If p > alpha, the null hypothesis cannot be rejected.
assert p > alpha


@pytest.mark.parametrize("func",
[dpnp.random.random,
dpnp.random.random_sample,
dpnp.random.randf,
dpnp.random.sample,
dpnp.random.rand],
ids=['random', 'random_sample',
'randf', 'sample',
'rand'])
def test_radnom_seed(func):
seed = 28041990
size = 100
shape = (100, 1)
if func in [dpnp.random.rand, dpnp.random.randn]:
args = size
else:
args = shape
dpnp.random.seed(seed)
a1 = func(args)
dpnp.random.seed(seed)
a2 = func(args)
assert_allclose(a1, a2, rtol=1e-07, atol=0)