|
1 | | -#!/usr/bin/env python |
2 | 1 | # Copyright (c) 2017, Intel Corporation |
3 | 2 | # |
4 | 3 | # Redistribution and use in source and binary forms, with or without |
@@ -67,15 +66,39 @@ def seed(self, seed=None): |
67 | 66 | For full documentation refer to `numpy.random.seed`. |
68 | 67 |
|
69 | 68 | """ |
70 | | - return super().seed(seed=seed, brng="MT19937") |
| 69 | + return super().seed(seed=seed) |
71 | 70 |
|
72 | 71 | def get_state(self, legacy=True): |
73 | 72 | """ |
74 | 73 | get_state(legacy=True) |
75 | 74 |
|
76 | 75 | Get the internal state of the generator. |
77 | 76 |
|
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`. |
79 | 102 |
|
80 | 103 | *Compatibility Notice* |
81 | 104 | As this class uses MKL in the backend, the state format is NOT |
@@ -119,12 +142,23 @@ def random_sample(self, size=None): |
119 | 142 | """ |
120 | 143 | return super().random_sample(size=size) |
121 | 144 |
|
| 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 | + |
122 | 156 | def randint(self, low, high=None, size=None, dtype=int): |
123 | 157 | """ |
124 | 158 | randint(low, high=None, size=None, dtype=int) |
125 | 159 |
|
126 | 160 | Return random integers from `low` (inclusive) to `high` (exclusive). |
127 | | - |
| 161 | +
|
128 | 162 | For full documentation refer to `numpy.random.randint`. |
129 | 163 |
|
130 | 164 | """ |
@@ -610,11 +644,31 @@ def __NPRandomState_ctor(): |
610 | 644 |
|
611 | 645 | # instantiate a default RandomState object to be used by module-level functions |
612 | 646 | _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 | + |
613 | 666 | # define module-level functions using methods of a default RandomState object |
614 | 667 | seed = _rand.seed |
615 | 668 | get_state = _rand.get_state |
616 | 669 | set_state = _rand.set_state |
617 | 670 | random_sample = _rand.random_sample |
| 671 | +random = _rand.random |
618 | 672 | choice = _rand.choice |
619 | 673 | randint = _rand.randint |
620 | 674 | bytes = _rand.bytes |
|
0 commit comments