_common.pxd 4.6 KB

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