@@ -21,7 +21,6 @@ cdef inline uint64_t _gen_mask(uint64_t max_val) nogil:
21
21
mask |= mask >> 16
22
22
mask |= mask >> 32
23
23
return mask
24
-
25
24
{{
26
25
py:
27
26
bc_ctypes = (('uint32', 'uint32', 'uint64', 'NPY_UINT64', 0, 0, 0, '0X100000000ULL'),
@@ -32,11 +31,8 @@ bc_ctypes = (('uint32', 'uint32', 'uint64', 'NPY_UINT64', 0, 0, 0, '0X100000000U
32
31
('int16', 'uint16', 'uint32', 'NPY_INT32', 1, 16, '-0x8000LL', '0x8000LL' ),
33
32
('int8', 'uint8', 'uint16', 'NPY_INT16', 3, 8, '-0x80LL', '0x80LL' ),
34
33
)}}
35
-
36
34
{{for nptype, utype, nptype_up, npctype, remaining, bitshift, lb, ub in bc_ctypes}}
37
-
38
35
{{ py: otype = nptype + '_' if nptype == 'bool' else nptype }}
39
-
40
36
cdef object _rand_{{nptype}}(object low, object high, object size, aug_state *state, object lock):
41
37
"""
42
38
_rand_{{nptype}}(low, high, size, *state, lock)
@@ -50,27 +46,27 @@ cdef object _rand_{{nptype}}(object low, object high, object size, aug_state *st
50
46
51
47
Parameters
52
48
----------
53
- low : int
49
+ low : int or array-like
54
50
Lowest (signed) integer to be drawn from the distribution (unless
55
51
``high=None``, in which case this parameter is the *highest* such
56
52
integer).
57
- high : int
53
+ high : int or array-like
58
54
If provided, the largest (signed) integer to be drawn from the
59
55
distribution (see above for behavior if ``high=None``).
60
56
size : int or tuple of ints
61
57
Output shape. If the given shape is, e.g., ``(m, n, k)``, then
62
58
``m * n * k`` samples are drawn. Default is None, in which case a
63
59
single value is returned.
64
- rngstate : encapsulated pointer to rk_state
65
- The specific type depends on the python version. In Python 2 it is
66
- a PyCObject, in Python 3 a PyCapsule object.
60
+ state : augmented random state
61
+ State to use in the core random number generators
62
+ lock : threading.Lock
63
+ Lock to prevent multiple using a single RandomState simultaneously
67
64
68
65
Returns
69
66
-------
70
67
out : python scalar or ndarray of np.{{nptype}}
71
68
`size`-shaped array of random integers from the appropriate
72
69
distribution, or a single such random int if `size` not provided.
73
-
74
70
"""
75
71
cdef {{utype}}_t rng, last_rng, off, val, mask, out_val
76
72
cdef uint32_t buf
@@ -150,45 +146,47 @@ cdef object _rand_{{nptype}}(object low, object high, object size, aug_state *st
150
146
151
147
return out_arr
152
148
{{endfor}}
153
-
154
-
155
149
{{
156
150
py:
157
151
big_bc_ctypes = (('uint64', 'uint64', 'NPY_UINT64', '0x0ULL', '0xFFFFFFFFFFFFFFFFULL'),
158
152
('int64', 'uint64', 'NPY_INT64', '-0x8000000000000000LL', '0x7FFFFFFFFFFFFFFFLL' )
159
153
)}}
160
-
161
154
{{for nptype, utype, npctype, lb, ub in big_bc_ctypes}}
162
-
163
155
{{ py: otype = nptype}}
164
-
165
156
cdef object _rand_{{nptype}}(object low, object high, object size, aug_state *state, object lock):
166
157
"""
167
- Generate bounded random {{nptype}} values
158
+ _rand_{{nptype}}(low, high, size, *state, lock)
159
+
160
+ Return random np.{{nptype}} integers between `low` and `high`, inclusive.
161
+
162
+ Return random integers from the "discrete uniform" distribution in the
163
+ closed interval [`low`, `high`). If `high` is None (the default),
164
+ then results are from [0, `low`). On entry the arguments are presumed
165
+ to have been validated for size and order for the np.{{nptype}} type.
168
166
169
167
Parameters
170
168
----------
171
169
low : int or array-like
172
- Array containing the lowest (signed) integers to be drawn from the
173
- distribution.
170
+ Lowest (signed) integer to be drawn from the distribution (unless
171
+ ``high=None``, in which case this parameter is the *highest* such
172
+ integer).
174
173
high : int or array-like
175
- Array containing the the open interval bound for the distribution.
174
+ If provided, the largest (signed) integer to be drawn from the
175
+ distribution (see above for behavior if ``high=None``).
176
176
size : int or tuple of ints
177
177
Output shape. If the given shape is, e.g., ``(m, n, k)``, then
178
- ``m * n * k`` samples are drawn. Default is None, in which case
179
- the output shape is determined by the broadcast shapes of low and
180
- high
178
+ ``m * n * k`` samples are drawn. Default is None, in which case a
179
+ single value is returned.
181
180
state : augmented random state
182
181
State to use in the core random number generators
183
182
lock : threading.Lock
184
183
Lock to prevent multiple using a single RandomState simultaneously
185
184
186
185
Returns
187
186
-------
188
- out : ndarray of np.{{nptype}}
189
- array of random integers from the appropriate distribution where the
190
- size is determined by size if provided or the broadcast shape of low
191
- and high
187
+ out : python scalar or ndarray of np.{{nptype}}
188
+ `size`-shaped array of random integers from the appropriate
189
+ distribution, or a single such random int if `size` not provided.
192
190
"""
193
191
cdef np.ndarray low_arr, high_arr, out_arr, highm1_arr
194
192
cdef np.npy_intp i, cnt
@@ -279,5 +277,4 @@ cdef object _rand_{{nptype}}(object low, object high, object size, aug_state *st
279
277
np.PyArray_MultiIter_NEXT(it)
280
278
281
279
return out_arr
282
-
283
280
{{endfor}}
0 commit comments