def NumPyRandomGeneratorType_standard_gamma(inst, shape, size=None, dtype=np.float64): check_types(shape, [types.Float, types.Integer, int, float], 'shape') dist_func, nb_dt = _get_proper_func(random_standard_gamma_f, random_standard_gamma, dtype) if isinstance(size, types.Omitted): size = size.value if is_nonelike(size): def impl(inst, shape, size=None, dtype=np.float64): return nb_dt(dist_func(inst.bit_generator, shape)) return impl else: check_size(size) def impl(inst, shape, size=None, dtype=np.float64): out = np.empty(size, dtype=dtype) for i in np.ndindex(size): out[i] = dist_func(inst.bit_generator, shape) return out return impl
def NumPyRandomGeneratorType_standard_exponential(inst, size=None, dtype=np.float64, method='zig'): check_types(method, [types.UnicodeType, str], 'method') dist_func_inv, nb_dt = _get_proper_func(random_standard_exponential_inv_f, random_standard_exponential_inv, dtype) dist_func, nb_dt = _get_proper_func(random_standard_exponential_f, random_standard_exponential, dtype) if isinstance(size, types.Omitted): size = size.value if is_nonelike(size): def impl(inst, size=None, dtype=np.float64, method='zig'): if method == 'zig': return nb_dt(dist_func(inst.bit_generator)) elif method == 'inv': return nb_dt(dist_func_inv(inst.bit_generator)) else: raise ValueError("Method must be either 'zig' or 'inv'") return impl else: check_size(size) def impl(inst, size=None, dtype=np.float64, method='zig'): out = np.empty(size, dtype=dtype) if method == 'zig': for i in np.ndindex(size): out[i] = dist_func(inst.bit_generator) elif method == 'inv': for i in np.ndindex(size): out[i] = dist_func_inv(inst.bit_generator) else: raise ValueError("Method must be either 'zig' or 'inv'") return out return impl
def NumPyRandomGeneratorType_poisson(inst, lam, size=None): check_types(lam, [types.Float, types.Integer, int, float], 'lam') if isinstance(size, types.Omitted): size = size.value if is_nonelike(size): def impl(inst, lam, size=None): return np.int64(random_poisson(inst.bit_generator, lam)) return impl else: check_size(size) def impl(inst, lam, size=None): out = np.empty(size, dtype=np.int64) for i in np.ndindex(size): out[i] = random_poisson(inst.bit_generator, lam) return out return impl
def NumPyRandomGeneratorType_standard_t(inst, df, size=None): check_types(df, [types.Float, types.Integer, int, float], 'df') if isinstance(size, types.Omitted): size = size.value if is_nonelike(size): def impl(inst, df, size=None): return random_standard_t(inst.bit_generator, df) return impl else: check_size(size) def impl(inst, df, size=None): out = np.empty(size) for i in np.ndindex(size): out[i] = random_standard_t(inst.bit_generator, df) return out return impl
def NumPyRandomGeneratorType_rayleigh(inst, scale=1.0, size=None): check_types(scale, [types.Float, types.Integer, int, float], 'scale') if isinstance(size, types.Omitted): size = size.value if is_nonelike(size): def impl(inst, scale=1.0, size=None): return random_rayleigh(inst.bit_generator, scale) return impl else: check_size(size) def impl(inst, scale=1.0, size=None): out = np.empty(size) for i in np.ndindex(size): out[i] = random_rayleigh(inst.bit_generator, scale) return out return impl
def NumPyRandomGeneratorType_standard_cauchy(inst, size=None): if isinstance(size, types.Omitted): size = size.value if is_nonelike(size): def impl(inst, size=None): return random_standard_cauchy(inst.bit_generator) return impl else: check_size(size) def impl(inst, size=None): out = np.empty(size) for i in np.ndindex(size): out[i] = random_standard_cauchy(inst.bit_generator) return out return impl
def NumPyRandomGeneratorType_negative_binomial(inst, n, p, size=None): check_types(n, [types.Float, types.Integer, int, float], 'n') check_types(p, [types.Float, types.Integer, int, float], 'p') if isinstance(size, types.Omitted): size = size.value if is_nonelike(size): def impl(inst, n, p, size=None): return np.int64(random_negative_binomial(inst.bit_generator, n, p)) return impl else: check_size(size) def impl(inst, n, p, size=None): out = np.empty(size, dtype=np.int64) for i in np.ndindex(size): out[i] = random_negative_binomial(inst.bit_generator, n, p) return out return impl
def NumPyRandomGeneratorType_lognormal(inst, mean=0.0, sigma=1.0, size=None): check_types(mean, [types.Float, types.Integer, int, float], 'mean') check_types(sigma, [types.Float, types.Integer, int, float], 'sigma') if isinstance(size, types.Omitted): size = size.value if is_nonelike(size): def impl(inst, mean=0.0, sigma=1.0, size=None): return random_lognormal(inst.bit_generator, mean, sigma) return impl else: check_size(size) def impl(inst, mean=0.0, sigma=1.0, size=None): out = np.empty(size) for i in np.ndindex(size): out[i] = random_lognormal(inst.bit_generator, mean, sigma) return out return impl
def NumPyRandomGeneratorType_beta(inst, a, b, size=None): check_types(a, [types.Float, types.Integer, int, float], 'a') check_types(b, [types.Float, types.Integer, int, float], 'b') if isinstance(size, types.Omitted): size = size.value if is_nonelike(size): def impl(inst, a, b, size=None): return random_beta(inst.bit_generator, a, b) return impl else: check_size(size) def impl(inst, a, b, size=None): out = np.empty(size) for i in np.ndindex(size): out[i] = random_beta(inst.bit_generator, a, b) return out return impl
def NumPyRandomGeneratorType_uniform(inst, low=0.0, high=1.0, size=None): check_types(low, [types.Float, types.Integer, int, float], 'low') check_types(high, [types.Float, types.Integer, int, float], 'high') if isinstance(size, types.Omitted): size = size.value if is_nonelike(size): def impl(inst, low=0.0, high=1.0, size=None): return random_uniform(inst.bit_generator, low, high - low) return impl else: check_size(size) def impl(inst, low=0.0, high=1.0, size=None): out = np.empty(size, dtype=np.float64) for i in np.ndindex(size): out[i] = random_uniform(inst.bit_generator, low, high - low) return out return impl
def NumPyRandomGeneratorType_random(inst, size=None, dtype=np.float64): dist_func, nb_dt = _get_proper_func(next_float, next_double, dtype, "random") if isinstance(size, types.Omitted): size = size.value if is_nonelike(size): def impl(inst, size=None, dtype=np.float64): return nb_dt(dist_func(inst.bit_generator)) return impl else: check_size(size) def impl(inst, size=None, dtype=np.float64): out = np.empty(size, dtype=dtype) for i in np.ndindex(size): out[i] = dist_func(inst.bit_generator) return out return impl
def NumPyRandomGeneratorType_triangular(inst, left, mode, right, size=None): check_types(left, [types.Float, types.Integer, int, float], 'left') check_types(mode, [types.Float, types.Integer, int, float], 'mode') check_types(right, [types.Float, types.Integer, int, float], 'right') if isinstance(size, types.Omitted): size = size.value if is_nonelike(size): def impl(inst, left, mode, right, size=None): return random_triangular(inst.bit_generator, left, mode, right) return impl else: check_size(size) def impl(inst, left, mode, right, size=None): out = np.empty(size) for i in np.ndindex(size): out[i] = random_triangular(inst.bit_generator, left, mode, right) return out return impl
def NumPyRandomGeneratorType_integers(inst, low, high, size=None, dtype=np.int64, endpoint=False): check_types(low, [types.Integer, types.Boolean, bool, int], 'low') check_types(high, [types.Integer, types.Boolean, bool, int], 'high') check_types(endpoint, [types.Boolean, bool], 'endpoint') if isinstance(size, types.Omitted): size = size.value if isinstance(dtype, types.Omitted): dtype = dtype.value if isinstance(dtype, type): nb_dt = from_dtype(np.dtype(dtype)) _dtype = dtype elif isinstance(dtype, types.NumberClass): nb_dt = dtype _dtype = as_dtype(nb_dt) else: raise TypingError("Argument dtype is not one of the" + " expected type(s): " + "np.int32, np.int64, np.int16, np.int8, " "np.uint32, np.uint64, np.uint16, np.uint8, " "np.bool_") if _dtype == np.bool_: int_func = random_methods.random_bounded_bool_fill lower_bound = -1 upper_bound = 2 else: try: i_info = np.iinfo(_dtype) except ValueError: raise TypingError("Argument dtype is not one of the" + " expected type(s): " + "np.int32, np.int64, np.int16, np.int8, " "np.uint32, np.uint64, np.uint16, np.uint8, " "np.bool_") int_func = getattr(random_methods, f'random_bounded_uint{i_info.bits}_fill') lower_bound = i_info.min upper_bound = i_info.max if is_nonelike(size): def impl(inst, low, high, size=None, dtype=np.int64, endpoint=False): random_methods._randint_arg_check(low, high, endpoint, lower_bound, upper_bound) if not endpoint: high -= dtype(1) low = dtype(low) high = dtype(high) rng = high - low return int_func(inst.bit_generator, low, rng, 1, dtype)[0] else: low = dtype(low) high = dtype(high) rng = high - low return int_func(inst.bit_generator, low, rng, 1, dtype)[0] return impl else: check_size(size) def impl(inst, low, high, size=None, dtype=np.int64, endpoint=False): random_methods._randint_arg_check(low, high, endpoint, lower_bound, upper_bound) if not endpoint: high -= dtype(1) low = dtype(low) high = dtype(high) rng = high - low return int_func(inst.bit_generator, low, rng, size, dtype) else: low = dtype(low) high = dtype(high) rng = high - low return int_func(inst.bit_generator, low, rng, size, dtype) return impl