Skip to content

Commit 14e0dac

Browse files
committed
address review comments
1 parent 5ffbb5a commit 14e0dac

File tree

8 files changed

+61
-11
lines changed

8 files changed

+61
-11
lines changed

mkl_random/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python
21
# Copyright (c) 2017, Intel Corporation
32
#
43
# Redistribution and use in source and binary forms, with or without

mkl_random/interfaces/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python
21
# Copyright (c) 2017, Intel Corporation
32
#
43
# Redistribution and use in source and binary forms, with or without
@@ -25,3 +24,6 @@
2524
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2625

2726
from . import numpy_random
27+
28+
# submodules
29+
__all__ = ["numpy_random"]

mkl_random/interfaces/_numpy_random.py

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python
21
# Copyright (c) 2017, Intel Corporation
32
#
43
# Redistribution and use in source and binary forms, with or without
@@ -67,15 +66,39 @@ def seed(self, seed=None):
6766
For full documentation refer to `numpy.random.seed`.
6867
6968
"""
70-
return super().seed(seed=seed, brng="MT19937")
69+
return super().seed(seed=seed)
7170

7271
def get_state(self, legacy=True):
7372
"""
7473
get_state(legacy=True)
7574
7675
Get the internal state of the generator.
7776
78-
For full documentation refer to `numpy.random.get_state`.
77+
Parameters
78+
----------
79+
legacy : bool, optional
80+
Flag indicating to return a legacy tuple state.
81+
82+
Returns
83+
-------
84+
out : {tuple(str, bytes), dict}
85+
The returned tuple has the following items:
86+
87+
1. a string specifying the basic psedo-random number generation
88+
algorithm. It should always be `MT19937` for this class.
89+
2. a bytes object holding content of Intel MKL's stream for the
90+
generator.
91+
92+
If `legacy` is False, a dictionary containing the state information is
93+
returned instead, with the following keys:
94+
1. `bit_generator`: a string specifying the basic psedo-random
95+
number generation algorithm. It should always be `MT19937` for
96+
this class.
97+
2. `state`: a dictionary guaranteed to contain the key
98+
`mkl_stream`, whose value is a bytes object holding content of
99+
Intel MKL's stream for the generator.
100+
101+
Compare with `numpy.random.get_state`.
79102
80103
*Compatibility Notice*
81104
As this class uses MKL in the backend, the state format is NOT
@@ -119,12 +142,23 @@ def random_sample(self, size=None):
119142
"""
120143
return super().random_sample(size=size)
121144

145+
def random(self, size=None):
146+
"""
147+
random(size=None)
148+
149+
Alias for `random_sample`.
150+
151+
For full documentation refer to `numpy.random.random_sample`.
152+
153+
"""
154+
return super().random_sample(size=size)
155+
122156
def randint(self, low, high=None, size=None, dtype=int):
123157
"""
124158
randint(low, high=None, size=None, dtype=int)
125159
126160
Return random integers from `low` (inclusive) to `high` (exclusive).
127-
161+
128162
For full documentation refer to `numpy.random.randint`.
129163
130164
"""
@@ -610,11 +644,31 @@ def __NPRandomState_ctor():
610644

611645
# instantiate a default RandomState object to be used by module-level functions
612646
_rand = RandomState()
647+
648+
649+
def sample(*args, **kwargs):
650+
"""
651+
Alias of `random_sample`.
652+
653+
For full documentation refer to `numpy.random.random_sample`.
654+
"""
655+
return _rand.random_sample(*args, **kwargs)
656+
657+
658+
def ranf(*args, **kwargs):
659+
"""
660+
Alias of `random_sample`.
661+
662+
For full documentation refer to `numpy.random.random_sample`.
663+
"""
664+
return _rand.random_sample(*args, **kwargs)
665+
613666
# define module-level functions using methods of a default RandomState object
614667
seed = _rand.seed
615668
get_state = _rand.get_state
616669
set_state = _rand.set_state
617670
random_sample = _rand.random_sample
671+
random = _rand.random
618672
choice = _rand.choice
619673
randint = _rand.randint
620674
bytes = _rand.bytes

mkl_random/interfaces/numpy_random.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python
21
# Copyright (c) 2017, Intel Corporation
32
#
43
# Redistribution and use in source and binary forms, with or without

mkl_random/mklrand.pyx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python
21
# Copyright (c) 2017, Intel Corporation
32
#
43
# Redistribution and use in source and binary forms, with or without

mkl_random/tests/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python
21
# Copyright (c) 2017, Intel Corporation
32
#
43
# Redistribution and use in source and binary forms, with or without

mkl_random/tests/test_random.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python
21
# Copyright (c) 2017, Intel Corporation
32
#
43
# Redistribution and use in source and binary forms, with or without

mkl_random/tests/test_regression.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python
21
# Copyright (c) 2017, Intel Corporation
32
#
43
# Redistribution and use in source and binary forms, with or without

0 commit comments

Comments
 (0)