_common.pxd
1 #cython: language_level=3 2 3 from libc.stdint cimport uint32_t, uint64_t, int32_t, int64_t 4 5 import numpy as np 6 cimport numpy as np 7 8 from numpy.random cimport bitgen_t 9 10 cdef double POISSON_LAM_MAX 11 cdef double LEGACY_POISSON_LAM_MAX 12 cdef uint64_t MAXSIZE 13 14 cdef enum ConstraintType: 15 CONS_NONE 16 CONS_NON_NEGATIVE 17 CONS_POSITIVE 18 CONS_POSITIVE_NOT_NAN 19 CONS_BOUNDED_0_1 20 CONS_BOUNDED_GT_0_1 21 CONS_BOUNDED_LT_0_1 22 CONS_GT_1 23 CONS_GTE_1 24 CONS_POISSON 25 LEGACY_CONS_POISSON 26 27 ctypedef ConstraintType constraint_type 28 29 cdef object benchmark(bitgen_t *bitgen, object lock, Py_ssize_t cnt, object method) 30 cdef object random_raw(bitgen_t *bitgen, object lock, object size, object output) 31 cdef object prepare_cffi(bitgen_t *bitgen) 32 cdef object prepare_ctypes(bitgen_t *bitgen) 33 cdef int check_constraint(double val, object name, constraint_type cons) except -1 34 cdef int check_array_constraint(np.ndarray val, object name, constraint_type cons) except -1 35 36 cdef extern from "include/aligned_malloc.h": 37 cdef void *PyArray_realloc_aligned(void *p, size_t n) 38 cdef void *PyArray_malloc_aligned(size_t n) 39 cdef void *PyArray_calloc_aligned(size_t n, size_t s) 40 cdef void PyArray_free_aligned(void *p) 41 42 ctypedef void (*random_double_fill)(bitgen_t *state, np.npy_intp count, double* out) nogil 43 ctypedef double (*random_double_0)(void *state) nogil 44 ctypedef double (*random_double_1)(void *state, double a) nogil 45 ctypedef double (*random_double_2)(void *state, double a, double b) nogil 46 ctypedef double (*random_double_3)(void *state, double a, double b, double c) nogil 47 48 ctypedef void (*random_float_fill)(bitgen_t *state, np.npy_intp count, float* out) nogil 49 ctypedef float (*random_float_0)(bitgen_t *state) nogil 50 ctypedef float (*random_float_1)(bitgen_t *state, float a) nogil 51 52 ctypedef int64_t (*random_uint_0)(void *state) nogil 53 ctypedef int64_t (*random_uint_d)(void *state, double a) nogil 54 ctypedef int64_t (*random_uint_dd)(void *state, double a, double b) nogil 55 ctypedef int64_t (*random_uint_di)(void *state, double a, uint64_t b) nogil 56 ctypedef int64_t (*random_uint_i)(void *state, int64_t a) nogil 57 ctypedef int64_t (*random_uint_iii)(void *state, int64_t a, int64_t b, int64_t c) nogil 58 59 ctypedef uint32_t (*random_uint_0_32)(bitgen_t *state) nogil 60 ctypedef uint32_t (*random_uint_1_i_32)(bitgen_t *state, uint32_t a) nogil 61 62 ctypedef int32_t (*random_int_2_i_32)(bitgen_t *state, int32_t a, int32_t b) nogil 63 ctypedef int64_t (*random_int_2_i)(bitgen_t *state, int64_t a, int64_t b) nogil 64 65 cdef double kahan_sum(double *darr, np.npy_intp n) 66 67 cdef inline double uint64_to_double(uint64_t rnd) nogil: 68 return (rnd >> 11) * (1.0 / 9007199254740992.0) 69 70 cdef object double_fill(void *func, bitgen_t *state, object size, object lock, object out) 71 72 cdef object float_fill(void *func, bitgen_t *state, object size, object lock, object out) 73 74 cdef object float_fill_from_double(void *func, bitgen_t *state, object size, object lock, object out) 75 76 cdef object wrap_int(object val, object bits) 77 78 cdef np.ndarray int_to_array(object value, object name, object bits, object uint_size) 79 80 cdef validate_output_shape(iter_shape, np.ndarray output) 81 82 cdef object cont(void *func, void *state, object size, object lock, int narg, 83 object a, object a_name, constraint_type a_constraint, 84 object b, object b_name, constraint_type b_constraint, 85 object c, object c_name, constraint_type c_constraint, 86 object out) 87 88 cdef object disc(void *func, void *state, object size, object lock, 89 int narg_double, int narg_int64, 90 object a, object a_name, constraint_type a_constraint, 91 object b, object b_name, constraint_type b_constraint, 92 object c, object c_name, constraint_type c_constraint) 93 94 cdef object cont_f(void *func, bitgen_t *state, object size, object lock, 95 object a, object a_name, constraint_type a_constraint, 96 object out) 97 98 cdef object cont_broadcast_3(void *func, void *state, object size, object lock, 99 np.ndarray a_arr, object a_name, constraint_type a_constraint, 100 np.ndarray b_arr, object b_name, constraint_type b_constraint, 101 np.ndarray c_arr, object c_name, constraint_type c_constraint) 102 103 cdef object discrete_broadcast_iii(void *func, void *state, object size, object lock, 104 np.ndarray a_arr, object a_name, constraint_type a_constraint, 105 np.ndarray b_arr, object b_name, constraint_type b_constraint, 106 np.ndarray c_arr, object c_name, constraint_type c_constraint)