diff options
author | gfyoung <gfyoung17@gmail.com> | 2016-09-23 17:55:14 -0400 |
---|---|---|
committer | gfyoung <gfyoung17@gmail.com> | 2016-09-23 17:55:20 -0400 |
commit | aef8d7c5e7f5673e7a12a2688e07312522a96b94 (patch) | |
tree | 90c20f0b925afa7e8fe7a5f11708c66dfdf35e9c /numpy/random | |
parent | 2de3dc4aa67f8842172d355b25889bf1c537de9c (diff) | |
download | python-numpy-aef8d7c5e7f5673e7a12a2688e07312522a96b94.tar.gz python-numpy-aef8d7c5e7f5673e7a12a2688e07312522a96b94.tar.bz2 python-numpy-aef8d7c5e7f5673e7a12a2688e07312522a96b94.zip |
MAINT: Remove duplicate randint helpers code.
Continuation of gh-8071 by removing the duplicate
randint Cython code that is not generated via Tempita.
Diffstat (limited to 'numpy/random')
-rw-r--r-- | numpy/random/mtrand/mtrand.pyx | 277 |
1 files changed, 0 insertions, 277 deletions
diff --git a/numpy/random/mtrand/mtrand.pyx b/numpy/random/mtrand/mtrand.pyx index eab8e59b3..1c7ffe9d5 100644 --- a/numpy/random/mtrand/mtrand.pyx +++ b/numpy/random/mtrand/mtrand.pyx @@ -573,283 +573,6 @@ def _shape_from_size(size, d): shape = tuple(size) + (d,) return shape - -# Set up dictionary of integer types and relevant functions. -# -# The dictionary is keyed by dtype(...).name and the values -# are a tuple (low, high, function), where low and high are -# the bounds of the largest half open interval `[low, high)` -# and the function is the relevant function to call for -# that precision. -# -# The functions are all the same except for changed types in -# a few places. It would be easy to template them. - -def _rand_bool(low, high, size, rngstate): - """ - _rand_bool(low, high, size, rngstate) - - See `_rand_int32` for documentation, only the return type changes. - - """ - cdef npy_bool off, rng, buf - cdef npy_bool *out - cdef ndarray array "arrayObject" - cdef npy_intp cnt - cdef rk_state *state = <rk_state *>PyCapsule_GetPointer(rngstate, NULL) - - rng = <npy_bool>(high - low) - off = <npy_bool>(low) - if size is None: - rk_random_bool(off, rng, 1, &buf, state) - return np.bool_(<npy_bool>buf) - else: - array = <ndarray>np.empty(size, np.bool_) - cnt = PyArray_SIZE(array) - out = <npy_bool *>PyArray_DATA(array) - with nogil: - rk_random_bool(off, rng, cnt, out, state) - return array - - -def _rand_int8(low, high, size, rngstate): - """ - _rand_int8(low, high, size, rngstate) - - See `_rand_int32` for documentation, only the return type changes. - - """ - cdef npy_uint8 off, rng, buf - cdef npy_uint8 *out - cdef ndarray array "arrayObject" - cdef npy_intp cnt - cdef rk_state *state = <rk_state *>PyCapsule_GetPointer(rngstate, NULL) - - rng = <npy_uint8>(high - low) - off = <npy_uint8>(<npy_int8>low) - if size is None: - rk_random_uint8(off, rng, 1, &buf, state) - return np.int8(<npy_int8>buf) - else: - array = <ndarray>np.empty(size, np.int8) - cnt = PyArray_SIZE(array) - out = <npy_uint8 *>PyArray_DATA(array) - with nogil: - rk_random_uint8(off, rng, cnt, out, state) - return array - - -def _rand_int16(low, high, size, rngstate): - """ - _rand_int16(low, high, size, rngstate) - - See `_rand_int32` for documentation, only the return type changes. - - """ - cdef npy_uint16 off, rng, buf - cdef npy_uint16 *out - cdef ndarray array "arrayObject" - cdef npy_intp cnt - cdef rk_state *state = <rk_state *>PyCapsule_GetPointer(rngstate, NULL) - - rng = <npy_uint16>(high - low) - off = <npy_uint16>(<npy_int16>low) - if size is None: - rk_random_uint16(off, rng, 1, &buf, state) - return np.int16(<npy_int16>buf) - else: - array = <ndarray>np.empty(size, np.int16) - cnt = PyArray_SIZE(array) - out = <npy_uint16 *>PyArray_DATA(array) - with nogil: - rk_random_uint16(off, rng, cnt, out, state) - return array - - -def _rand_int32(low, high, size, rngstate): - """ - _rand_int32(self, low, high, size, rngstate) - - Return random np.int32 integers between `low` and `high`, inclusive. - - Return random integers from the "discrete uniform" distribution in the - closed interval [`low`, `high`]. On entry the arguments are presumed - to have been validated for size and order for the np.int32 type. - - Parameters - ---------- - low : int - Lowest (signed) integer to be drawn from the distribution. - high : int - Highest (signed) integer to be drawn from the distribution. - size : int or tuple of ints - Output shape. If the given shape is, e.g., ``(m, n, k)``, then - ``m * n * k`` samples are drawn. Default is None, in which case a - single value is returned. - rngstate : encapsulated pointer to rk_state - The specific type depends on the python version. In Python 2 it is - a PyCObject, in Python 3 a PyCapsule object. - - Returns - ------- - out : python scalar or ndarray of np.int32 - `size`-shaped array of random integers from the appropriate - distribution, or a single such random int if `size` not provided. - - """ - cdef npy_uint32 off, rng, buf - cdef npy_uint32 *out - cdef ndarray array "arrayObject" - cdef npy_intp cnt - cdef rk_state *state = <rk_state *>PyCapsule_GetPointer(rngstate, NULL) - - rng = <npy_uint32>(high - low) - off = <npy_uint32>(<npy_int32>low) - if size is None: - rk_random_uint32(off, rng, 1, &buf, state) - return np.int32(<npy_int32>buf) - else: - array = <ndarray>np.empty(size, np.int32) - cnt = PyArray_SIZE(array) - out = <npy_uint32 *>PyArray_DATA(array) - with nogil: - rk_random_uint32(off, rng, cnt, out, state) - return array - - -def _rand_int64(low, high, size, rngstate): - """ - _rand_int64(low, high, size, rngstate) - - See `_rand_int32` for documentation, only the return type changes. - - """ - cdef npy_uint64 off, rng, buf - cdef npy_uint64 *out - cdef ndarray array "arrayObject" - cdef npy_intp cnt - cdef rk_state *state = <rk_state *>PyCapsule_GetPointer(rngstate, NULL) - - rng = <npy_uint64>(high - low) - off = <npy_uint64>(<npy_int64>low) - if size is None: - rk_random_uint64(off, rng, 1, &buf, state) - return np.int64(<npy_int64>buf) - else: - array = <ndarray>np.empty(size, np.int64) - cnt = PyArray_SIZE(array) - out = <npy_uint64 *>PyArray_DATA(array) - with nogil: - rk_random_uint64(off, rng, cnt, out, state) - return array - -def _rand_uint8(low, high, size, rngstate): - """ - _rand_uint8(low, high, size, rngstate) - - See `_rand_int32` for documentation, only the return type changes. - - """ - cdef npy_uint8 off, rng, buf - cdef npy_uint8 *out - cdef ndarray array "arrayObject" - cdef npy_intp cnt - cdef rk_state *state = <rk_state *>PyCapsule_GetPointer(rngstate, NULL) - - rng = <npy_uint8>(high - low) - off = <npy_uint8>(low) - if size is None: - rk_random_uint8(off, rng, 1, &buf, state) - return np.uint8(<npy_uint8>buf) - else: - array = <ndarray>np.empty(size, np.uint8) - cnt = PyArray_SIZE(array) - out = <npy_uint8 *>PyArray_DATA(array) - with nogil: - rk_random_uint8(off, rng, cnt, out, state) - return array - - -def _rand_uint16(low, high, size, rngstate): - """ - _rand_uint16(low, high, size, rngstate) - - See `_rand_int32` for documentation, only the return type changes. - - """ - cdef npy_uint16 off, rng, buf - cdef npy_uint16 *out - cdef ndarray array "arrayObject" - cdef npy_intp cnt - cdef rk_state *state = <rk_state *>PyCapsule_GetPointer(rngstate, NULL) - - rng = <npy_uint16>(high - low) - off = <npy_uint16>(low) - if size is None: - rk_random_uint16(off, rng, 1, &buf, state) - return np.uint16(<npy_uint16>buf) - else: - array = <ndarray>np.empty(size, np.uint16) - cnt = PyArray_SIZE(array) - out = <npy_uint16 *>PyArray_DATA(array) - with nogil: - rk_random_uint16(off, rng, cnt, out, state) - return array - - -def _rand_uint32(low, high, size, rngstate): - """ - _rand_uint32(self, low, high, size, rngstate) - - See `_rand_int32` for documentation, only the return type changes. - - """ - cdef npy_uint32 off, rng, buf - cdef npy_uint32 *out - cdef ndarray array "arrayObject" - cdef npy_intp cnt - cdef rk_state *state = <rk_state *>PyCapsule_GetPointer(rngstate, NULL) - - rng = <npy_uint32>(high - low) - off = <npy_uint32>(low) - if size is None: - rk_random_uint32(off, rng, 1, &buf, state) - return np.uint32(<npy_uint32>buf) - else: - array = <ndarray>np.empty(size, np.uint32) - cnt = PyArray_SIZE(array) - out = <npy_uint32 *>PyArray_DATA(array) - with nogil: - rk_random_uint32(off, rng, cnt, out, state) - return array - - -def _rand_uint64(low, high, size, rngstate): - """ - _rand_uint64(low, high, size, rngstate) - - See `_rand_int32` for documentation, only the return type changes. - - """ - cdef npy_uint64 off, rng, buf - cdef npy_uint64 *out - cdef ndarray array "arrayObject" - cdef npy_intp cnt - cdef rk_state *state = <rk_state *>PyCapsule_GetPointer(rngstate, NULL) - - rng = <npy_uint64>(high - low) - off = <npy_uint64>(low) - if size is None: - rk_random_uint64(off, rng, 1, &buf, state) - return np.uint64(<npy_uint64>buf) - else: - array = <ndarray>np.empty(size, np.uint64) - cnt = PyArray_SIZE(array) - out = <npy_uint64 *>PyArray_DATA(array) - with nogil: - rk_random_uint64(off, rng, cnt, out, state) - return array - # Look up table for randint functions keyed by type name. The stored data # is a tuple (lbnd, ubnd, func), where lbnd is the smallest value for the # type, ubnd is one greater than the largest value, and func is the |