1
#ifndef _RANDOMDGEN__DISTRIBUTIONS_H_
2
#define _RANDOMDGEN__DISTRIBUTIONS_H_
3

4
#include "Python.h"
5
#include "numpy/npy_common.h"
6
#include <stddef.h>
7
#include <stdbool.h>
8
#include <stdint.h>
9

10
#include "numpy/npy_math.h"
11
#include "numpy/random/bitgen.h"
12

13
/*
14
 * RAND_INT_TYPE is used to share integer generators with RandomState which
15
 * used long in place of int64_t. If changing a distribution that uses
16
 * RAND_INT_TYPE, then the original unmodified copy must be retained for
17
 * use in RandomState by copying to the legacy distributions source file.
18
 */
19
#ifdef NP_RANDOM_LEGACY
20
#define RAND_INT_TYPE long
21
#define RAND_INT_MAX LONG_MAX
22
#else
23
#define RAND_INT_TYPE int64_t
24
#define RAND_INT_MAX INT64_MAX
25
#endif
26

27
#ifdef _MSC_VER
28
#define DECLDIR __declspec(dllexport)
29
#else
30
#define DECLDIR extern
31
#endif
32

33
#ifndef MIN
34
#define MIN(x, y) (((x) < (y)) ? x : y)
35
#define MAX(x, y) (((x) > (y)) ? x : y)
36
#endif
37

38
#ifndef M_PI
39
#define M_PI 3.14159265358979323846264338328
40
#endif
41

42
typedef struct s_binomial_t {
43
  int has_binomial; /* !=0: following parameters initialized for binomial */
44
  double psave;
45
  RAND_INT_TYPE nsave;
46
  double r;
47
  double q;
48
  double fm;
49
  RAND_INT_TYPE m;
50
  double p1;
51
  double xm;
52
  double xl;
53
  double xr;
54
  double c;
55
  double laml;
56
  double lamr;
57
  double p2;
58
  double p3;
59
  double p4;
60
} binomial_t;
61

62
DECLDIR float random_standard_uniform_f(bitgen_t *bitgen_state);
63
DECLDIR double random_standard_uniform(bitgen_t *bitgen_state);
64
DECLDIR void random_standard_uniform_fill(bitgen_t *, npy_intp, double *);
65
DECLDIR void random_standard_uniform_fill_f(bitgen_t *, npy_intp, float *);
66

67
DECLDIR int64_t random_positive_int64(bitgen_t *bitgen_state);
68
DECLDIR int32_t random_positive_int32(bitgen_t *bitgen_state);
69
DECLDIR int64_t random_positive_int(bitgen_t *bitgen_state);
70
DECLDIR uint64_t random_uint(bitgen_t *bitgen_state);
71

72
DECLDIR double random_standard_exponential(bitgen_t *bitgen_state);
73
DECLDIR float random_standard_exponential_f(bitgen_t *bitgen_state);
74
DECLDIR void random_standard_exponential_fill(bitgen_t *, npy_intp, double *);
75
DECLDIR void random_standard_exponential_fill_f(bitgen_t *, npy_intp, float *);
76
DECLDIR void random_standard_exponential_inv_fill(bitgen_t *, npy_intp, double *);
77
DECLDIR void random_standard_exponential_inv_fill_f(bitgen_t *, npy_intp, float *);
78

79
DECLDIR double random_standard_normal(bitgen_t *bitgen_state);
80
DECLDIR float random_standard_normal_f(bitgen_t *bitgen_state);
81
DECLDIR void random_standard_normal_fill(bitgen_t *, npy_intp, double *);
82
DECLDIR void random_standard_normal_fill_f(bitgen_t *, npy_intp, float *);
83
DECLDIR double random_standard_gamma(bitgen_t *bitgen_state, double shape);
84
DECLDIR float random_standard_gamma_f(bitgen_t *bitgen_state, float shape);
85

86
DECLDIR double random_normal(bitgen_t *bitgen_state, double loc, double scale);
87

88
DECLDIR double random_gamma(bitgen_t *bitgen_state, double shape, double scale);
89
DECLDIR float random_gamma_f(bitgen_t *bitgen_state, float shape, float scale);
90

91
DECLDIR double random_exponential(bitgen_t *bitgen_state, double scale);
92
DECLDIR double random_uniform(bitgen_t *bitgen_state, double lower, double range);
93
DECLDIR double random_beta(bitgen_t *bitgen_state, double a, double b);
94
DECLDIR double random_chisquare(bitgen_t *bitgen_state, double df);
95
DECLDIR double random_f(bitgen_t *bitgen_state, double dfnum, double dfden);
96
DECLDIR double random_standard_cauchy(bitgen_t *bitgen_state);
97
DECLDIR double random_pareto(bitgen_t *bitgen_state, double a);
98
DECLDIR double random_weibull(bitgen_t *bitgen_state, double a);
99
DECLDIR double random_power(bitgen_t *bitgen_state, double a);
100
DECLDIR double random_laplace(bitgen_t *bitgen_state, double loc, double scale);
101
DECLDIR double random_gumbel(bitgen_t *bitgen_state, double loc, double scale);
102
DECLDIR double random_logistic(bitgen_t *bitgen_state, double loc, double scale);
103
DECLDIR double random_lognormal(bitgen_t *bitgen_state, double mean, double sigma);
104
DECLDIR double random_rayleigh(bitgen_t *bitgen_state, double mode);
105
DECLDIR double random_standard_t(bitgen_t *bitgen_state, double df);
106
DECLDIR double random_noncentral_chisquare(bitgen_t *bitgen_state, double df,
107
                                           double nonc);
108
DECLDIR double random_noncentral_f(bitgen_t *bitgen_state, double dfnum,
109
                                   double dfden, double nonc);
110
DECLDIR double random_wald(bitgen_t *bitgen_state, double mean, double scale);
111
DECLDIR double random_vonmises(bitgen_t *bitgen_state, double mu, double kappa);
112
DECLDIR double random_triangular(bitgen_t *bitgen_state, double left, double mode,
113
                                 double right);
114

115
DECLDIR RAND_INT_TYPE random_poisson(bitgen_t *bitgen_state, double lam);
116
DECLDIR RAND_INT_TYPE random_negative_binomial(bitgen_t *bitgen_state, double n,
117
                                 double p);
118

119
DECLDIR int64_t random_binomial(bitgen_t *bitgen_state, double p,
120
                                int64_t n, binomial_t *binomial);
121

122
DECLDIR RAND_INT_TYPE random_logseries(bitgen_t *bitgen_state, double p);
123
DECLDIR RAND_INT_TYPE random_geometric(bitgen_t *bitgen_state, double p);
124
DECLDIR RAND_INT_TYPE random_zipf(bitgen_t *bitgen_state, double a);
125
DECLDIR int64_t random_hypergeometric(bitgen_t *bitgen_state,
126
                                      int64_t good, int64_t bad, int64_t sample);
127
DECLDIR uint64_t random_interval(bitgen_t *bitgen_state, uint64_t max);
128

129
/* Generate random uint64 numbers in closed interval [off, off + rng]. */
130
DECLDIR uint64_t random_bounded_uint64(bitgen_t *bitgen_state, uint64_t off,
131
                                       uint64_t rng, uint64_t mask,
132
                                       bool use_masked);
133

134
/* Generate random uint32 numbers in closed interval [off, off + rng]. */
135
DECLDIR uint32_t random_buffered_bounded_uint32(bitgen_t *bitgen_state,
136
                                                uint32_t off, uint32_t rng,
137
                                                uint32_t mask, bool use_masked,
138
                                                int *bcnt, uint32_t *buf);
139
DECLDIR uint16_t random_buffered_bounded_uint16(bitgen_t *bitgen_state,
140
                                                uint16_t off, uint16_t rng,
141
                                                uint16_t mask, bool use_masked,
142
                                                int *bcnt, uint32_t *buf);
143
DECLDIR uint8_t random_buffered_bounded_uint8(bitgen_t *bitgen_state, uint8_t off,
144
                                              uint8_t rng, uint8_t mask,
145
                                              bool use_masked, int *bcnt,
146
                                              uint32_t *buf);
147
DECLDIR npy_bool random_buffered_bounded_bool(bitgen_t *bitgen_state, npy_bool off,
148
                                              npy_bool rng, npy_bool mask,
149
                                              bool use_masked, int *bcnt,
150
                                              uint32_t *buf);
151

152
DECLDIR void random_bounded_uint64_fill(bitgen_t *bitgen_state, uint64_t off,
153
                                        uint64_t rng, npy_intp cnt,
154
                                        bool use_masked, uint64_t *out);
155
DECLDIR void random_bounded_uint32_fill(bitgen_t *bitgen_state, uint32_t off,
156
                                        uint32_t rng, npy_intp cnt,
157
                                        bool use_masked, uint32_t *out);
158
DECLDIR void random_bounded_uint16_fill(bitgen_t *bitgen_state, uint16_t off,
159
                                        uint16_t rng, npy_intp cnt,
160
                                        bool use_masked, uint16_t *out);
161
DECLDIR void random_bounded_uint8_fill(bitgen_t *bitgen_state, uint8_t off,
162
                                       uint8_t rng, npy_intp cnt,
163
                                       bool use_masked, uint8_t *out);
164
DECLDIR void random_bounded_bool_fill(bitgen_t *bitgen_state, npy_bool off,
165
                                      npy_bool rng, npy_intp cnt,
166
                                      bool use_masked, npy_bool *out);
167

168
DECLDIR void random_multinomial(bitgen_t *bitgen_state, RAND_INT_TYPE n, RAND_INT_TYPE *mnix,
169
                                double *pix, npy_intp d, binomial_t *binomial);
170

171
/* multivariate hypergeometric, "count" method */
172
DECLDIR int random_multivariate_hypergeometric_count(bitgen_t *bitgen_state,
173
                              int64_t total,
174
                              size_t num_colors, int64_t *colors,
175
                              int64_t nsample,
176
                              size_t num_variates, int64_t *variates);
177

178
/* multivariate hypergeometric, "marginals" method */
179
DECLDIR void random_multivariate_hypergeometric_marginals(bitgen_t *bitgen_state,
180
                                   int64_t total,
181
                                   size_t num_colors, int64_t *colors,
182
                                   int64_t nsample,
183
                                   size_t num_variates, int64_t *variates);
184

185
/* Common to legacy-distributions.c and distributions.c but not exported */
186

187
RAND_INT_TYPE random_binomial_btpe(bitgen_t *bitgen_state,
188
                                   RAND_INT_TYPE n,
189
                                   double p,
190
                                   binomial_t *binomial);
191
RAND_INT_TYPE random_binomial_inversion(bitgen_t *bitgen_state,
192
                                        RAND_INT_TYPE n,
193
                                        double p,
194
                                        binomial_t *binomial);
195
double random_loggam(double x);
196
static NPY_INLINE double next_double(bitgen_t *bitgen_state) {
197 1
    return bitgen_state->next_double(bitgen_state->state);
198
}
199

200
#endif

Read our documentation on viewing source code .

Loading