Rename probability distribution names to end with "_t".

I needed to do this by hand, since we also use these for function
names, variable names, macro expansion, and a little token pasting.
This commit is contained in:
Nick Mathewson 2019-11-07 08:55:23 -05:00
parent 0644530df2
commit 31a6a6512f
4 changed files with 127 additions and 123 deletions

View File

@ -688,7 +688,7 @@ circpad_distribution_sample(circpad_distribution_t dist)
case CIRCPAD_DIST_UNIFORM: case CIRCPAD_DIST_UNIFORM:
{ {
// param2 is upper bound, param1 is lower // param2 is upper bound, param1 is lower
const struct uniform my_uniform = { const struct uniform_t my_uniform = {
.base = UNIFORM(my_uniform), .base = UNIFORM(my_uniform),
.a = dist.param1, .a = dist.param1,
.b = dist.param2, .b = dist.param2,
@ -698,7 +698,7 @@ circpad_distribution_sample(circpad_distribution_t dist)
case CIRCPAD_DIST_LOGISTIC: case CIRCPAD_DIST_LOGISTIC:
{ {
/* param1 is Mu, param2 is sigma. */ /* param1 is Mu, param2 is sigma. */
const struct logistic my_logistic = { const struct logistic_t my_logistic = {
.base = LOGISTIC(my_logistic), .base = LOGISTIC(my_logistic),
.mu = dist.param1, .mu = dist.param1,
.sigma = dist.param2, .sigma = dist.param2,
@ -708,7 +708,7 @@ circpad_distribution_sample(circpad_distribution_t dist)
case CIRCPAD_DIST_LOG_LOGISTIC: case CIRCPAD_DIST_LOG_LOGISTIC:
{ {
/* param1 is Alpha, param2 is 1.0/Beta */ /* param1 is Alpha, param2 is 1.0/Beta */
const struct log_logistic my_log_logistic = { const struct log_logistic_t my_log_logistic = {
.base = LOG_LOGISTIC(my_log_logistic), .base = LOG_LOGISTIC(my_log_logistic),
.alpha = dist.param1, .alpha = dist.param1,
.beta = dist.param2, .beta = dist.param2,
@ -718,7 +718,7 @@ circpad_distribution_sample(circpad_distribution_t dist)
case CIRCPAD_DIST_GEOMETRIC: case CIRCPAD_DIST_GEOMETRIC:
{ {
/* param1 is 'p' (success probability) */ /* param1 is 'p' (success probability) */
const struct geometric my_geometric = { const struct geometric_t my_geometric = {
.base = GEOMETRIC(my_geometric), .base = GEOMETRIC(my_geometric),
.p = dist.param1, .p = dist.param1,
}; };
@ -727,7 +727,7 @@ circpad_distribution_sample(circpad_distribution_t dist)
case CIRCPAD_DIST_WEIBULL: case CIRCPAD_DIST_WEIBULL:
{ {
/* param1 is k, param2 is Lambda */ /* param1 is k, param2 is Lambda */
const struct weibull my_weibull = { const struct weibull_t my_weibull = {
.base = WEIBULL(my_weibull), .base = WEIBULL(my_weibull),
.k = dist.param1, .k = dist.param1,
.lambda = dist.param2, .lambda = dist.param2,
@ -737,7 +737,7 @@ circpad_distribution_sample(circpad_distribution_t dist)
case CIRCPAD_DIST_PARETO: case CIRCPAD_DIST_PARETO:
{ {
/* param1 is sigma, param2 is xi, no more params for mu so we use 0 */ /* param1 is sigma, param2 is xi, no more params for mu so we use 0 */
const struct genpareto my_genpareto = { const struct genpareto_t my_genpareto = {
.base = GENPARETO(my_genpareto), .base = GENPARETO(my_genpareto),
.mu = 0, .mu = 0,
.sigma = dist.param1, .sigma = dist.param1,

View File

@ -52,14 +52,15 @@
#include <math.h> #include <math.h>
#include <stddef.h> #include <stddef.h>
#ifndef COCCI
/** Declare a function that downcasts from a generic dist struct to the actual /** Declare a function that downcasts from a generic dist struct to the actual
* subtype probablity distribution it represents. */ * subtype probablity distribution it represents. */
#define DECLARE_PROB_DISTR_DOWNCAST_FN(name) \ #define DECLARE_PROB_DISTR_DOWNCAST_FN(name) \
static inline \ static inline \
const struct name * \ const struct name##_t * \
dist_to_const_##name(const struct dist *obj) { \ dist_to_const_##name(const struct dist_t *obj) { \
tor_assert(obj->ops == &name##_ops); \ tor_assert(obj->ops == &name##_ops); \
return SUBTYPE_P(obj, struct name, base); \ return SUBTYPE_P(obj, struct name ## _t, base); \
} }
DECLARE_PROB_DISTR_DOWNCAST_FN(uniform) DECLARE_PROB_DISTR_DOWNCAST_FN(uniform)
DECLARE_PROB_DISTR_DOWNCAST_FN(geometric) DECLARE_PROB_DISTR_DOWNCAST_FN(geometric)
@ -67,6 +68,7 @@ DECLARE_PROB_DISTR_DOWNCAST_FN(logistic)
DECLARE_PROB_DISTR_DOWNCAST_FN(log_logistic) DECLARE_PROB_DISTR_DOWNCAST_FN(log_logistic)
DECLARE_PROB_DISTR_DOWNCAST_FN(genpareto) DECLARE_PROB_DISTR_DOWNCAST_FN(genpareto)
DECLARE_PROB_DISTR_DOWNCAST_FN(weibull) DECLARE_PROB_DISTR_DOWNCAST_FN(weibull)
#endif
/** /**
* Count number of one bits in 32-bit word. * Count number of one bits in 32-bit word.
@ -1324,42 +1326,42 @@ sample_geometric(uint32_t s, double p0, double p)
/** Returns the name of the distribution in <b>dist</b>. */ /** Returns the name of the distribution in <b>dist</b>. */
const char * const char *
dist_name(const struct dist *dist) dist_name(const struct dist_t *dist)
{ {
return dist->ops->name; return dist->ops->name;
} }
/* Sample a value from <b>dist</b> and return it. */ /* Sample a value from <b>dist</b> and return it. */
double double
dist_sample(const struct dist *dist) dist_sample(const struct dist_t *dist)
{ {
return dist->ops->sample(dist); return dist->ops->sample(dist);
} }
/** Compute the CDF of <b>dist</b> at <b>x</b>. */ /** Compute the CDF of <b>dist</b> at <b>x</b>. */
double double
dist_cdf(const struct dist *dist, double x) dist_cdf(const struct dist_t *dist, double x)
{ {
return dist->ops->cdf(dist, x); return dist->ops->cdf(dist, x);
} }
/** Compute the SF (Survival function) of <b>dist</b> at <b>x</b>. */ /** Compute the SF (Survival function) of <b>dist</b> at <b>x</b>. */
double double
dist_sf(const struct dist *dist, double x) dist_sf(const struct dist_t *dist, double x)
{ {
return dist->ops->sf(dist, x); return dist->ops->sf(dist, x);
} }
/** Compute the iCDF (Inverse CDF) of <b>dist</b> at <b>x</b>. */ /** Compute the iCDF (Inverse CDF) of <b>dist</b> at <b>x</b>. */
double double
dist_icdf(const struct dist *dist, double p) dist_icdf(const struct dist_t *dist, double p)
{ {
return dist->ops->icdf(dist, p); return dist->ops->icdf(dist, p);
} }
/** Compute the iSF (Inverse Survival function) of <b>dist</b> at <b>x</b>. */ /** Compute the iSF (Inverse Survival function) of <b>dist</b> at <b>x</b>. */
double double
dist_isf(const struct dist *dist, double p) dist_isf(const struct dist_t *dist, double p)
{ {
return dist->ops->isf(dist, p); return dist->ops->isf(dist, p);
} }
@ -1367,18 +1369,18 @@ dist_isf(const struct dist *dist, double p)
/** Functions for uniform distribution */ /** Functions for uniform distribution */
static double static double
uniform_sample(const struct dist *dist) uniform_sample(const struct dist_t *dist)
{ {
const struct uniform *U = dist_to_const_uniform(dist); const struct uniform_t *U = dist_to_const_uniform(dist);
double p0 = random_uniform_01(); double p0 = random_uniform_01();
return sample_uniform_interval(p0, U->a, U->b); return sample_uniform_interval(p0, U->a, U->b);
} }
static double static double
uniform_cdf(const struct dist *dist, double x) uniform_cdf(const struct dist_t *dist, double x)
{ {
const struct uniform *U = dist_to_const_uniform(dist); const struct uniform_t *U = dist_to_const_uniform(dist);
if (x < U->a) if (x < U->a)
return 0; return 0;
else if (x < U->b) else if (x < U->b)
@ -1388,9 +1390,9 @@ uniform_cdf(const struct dist *dist, double x)
} }
static double static double
uniform_sf(const struct dist *dist, double x) uniform_sf(const struct dist_t *dist, double x)
{ {
const struct uniform *U = dist_to_const_uniform(dist); const struct uniform_t *U = dist_to_const_uniform(dist);
if (x > U->b) if (x > U->b)
return 0; return 0;
@ -1401,18 +1403,18 @@ uniform_sf(const struct dist *dist, double x)
} }
static double static double
uniform_icdf(const struct dist *dist, double p) uniform_icdf(const struct dist_t *dist, double p)
{ {
const struct uniform *U = dist_to_const_uniform(dist); const struct uniform_t *U = dist_to_const_uniform(dist);
double w = U->b - U->a; double w = U->b - U->a;
return (p < 0.5 ? (U->a + w*p) : (U->b - w*(1 - p))); return (p < 0.5 ? (U->a + w*p) : (U->b - w*(1 - p)));
} }
static double static double
uniform_isf(const struct dist *dist, double p) uniform_isf(const struct dist_t *dist, double p)
{ {
const struct uniform *U = dist_to_const_uniform(dist); const struct uniform_t *U = dist_to_const_uniform(dist);
double w = U->b - U->a; double w = U->b - U->a;
return (p < 0.5 ? (U->b - w*p) : (U->a + w*(1 - p))); return (p < 0.5 ? (U->b - w*p) : (U->a + w*(1 - p)));
@ -1434,9 +1436,9 @@ const struct dist_ops_t uniform_ops = {
/** Functions for logistic distribution: */ /** Functions for logistic distribution: */
static double static double
logistic_sample(const struct dist *dist) logistic_sample(const struct dist_t *dist)
{ {
const struct logistic *L = dist_to_const_logistic(dist); const struct logistic_t *L = dist_to_const_logistic(dist);
uint32_t s = crypto_fast_rng_get_u32(get_thread_fast_rng()); uint32_t s = crypto_fast_rng_get_u32(get_thread_fast_rng());
double t = random_uniform_01(); double t = random_uniform_01();
double p0 = random_uniform_01(); double p0 = random_uniform_01();
@ -1445,30 +1447,30 @@ logistic_sample(const struct dist *dist)
} }
static double static double
logistic_cdf(const struct dist *dist, double x) logistic_cdf(const struct dist_t *dist, double x)
{ {
const struct logistic *L = dist_to_const_logistic(dist); const struct logistic_t *L = dist_to_const_logistic(dist);
return cdf_logistic(x, L->mu, L->sigma); return cdf_logistic(x, L->mu, L->sigma);
} }
static double static double
logistic_sf(const struct dist *dist, double x) logistic_sf(const struct dist_t *dist, double x)
{ {
const struct logistic *L = dist_to_const_logistic(dist); const struct logistic_t *L = dist_to_const_logistic(dist);
return sf_logistic(x, L->mu, L->sigma); return sf_logistic(x, L->mu, L->sigma);
} }
static double static double
logistic_icdf(const struct dist *dist, double p) logistic_icdf(const struct dist_t *dist, double p)
{ {
const struct logistic *L = dist_to_const_logistic(dist); const struct logistic_t *L = dist_to_const_logistic(dist);
return icdf_logistic(p, L->mu, L->sigma); return icdf_logistic(p, L->mu, L->sigma);
} }
static double static double
logistic_isf(const struct dist *dist, double p) logistic_isf(const struct dist_t *dist, double p)
{ {
const struct logistic *L = dist_to_const_logistic(dist); const struct logistic_t *L = dist_to_const_logistic(dist);
return isf_logistic(p, L->mu, L->sigma); return isf_logistic(p, L->mu, L->sigma);
} }
@ -1484,9 +1486,9 @@ const struct dist_ops_t logistic_ops = {
/** Functions for log-logistic distribution: */ /** Functions for log-logistic distribution: */
static double static double
log_logistic_sample(const struct dist *dist) log_logistic_sample(const struct dist_t *dist)
{ {
const struct log_logistic *LL = dist_to_const_log_logistic(dist); const struct log_logistic_t *LL = dist_to_const_log_logistic(dist);
uint32_t s = crypto_fast_rng_get_u32(get_thread_fast_rng()); uint32_t s = crypto_fast_rng_get_u32(get_thread_fast_rng());
double p0 = random_uniform_01(); double p0 = random_uniform_01();
@ -1494,30 +1496,30 @@ log_logistic_sample(const struct dist *dist)
} }
static double static double
log_logistic_cdf(const struct dist *dist, double x) log_logistic_cdf(const struct dist_t *dist, double x)
{ {
const struct log_logistic *LL = dist_to_const_log_logistic(dist); const struct log_logistic_t *LL = dist_to_const_log_logistic(dist);
return cdf_log_logistic(x, LL->alpha, LL->beta); return cdf_log_logistic(x, LL->alpha, LL->beta);
} }
static double static double
log_logistic_sf(const struct dist *dist, double x) log_logistic_sf(const struct dist_t *dist, double x)
{ {
const struct log_logistic *LL = dist_to_const_log_logistic(dist); const struct log_logistic_t *LL = dist_to_const_log_logistic(dist);
return sf_log_logistic(x, LL->alpha, LL->beta); return sf_log_logistic(x, LL->alpha, LL->beta);
} }
static double static double
log_logistic_icdf(const struct dist *dist, double p) log_logistic_icdf(const struct dist_t *dist, double p)
{ {
const struct log_logistic *LL = dist_to_const_log_logistic(dist); const struct log_logistic_t *LL = dist_to_const_log_logistic(dist);
return icdf_log_logistic(p, LL->alpha, LL->beta); return icdf_log_logistic(p, LL->alpha, LL->beta);
} }
static double static double
log_logistic_isf(const struct dist *dist, double p) log_logistic_isf(const struct dist_t *dist, double p)
{ {
const struct log_logistic *LL = dist_to_const_log_logistic(dist); const struct log_logistic_t *LL = dist_to_const_log_logistic(dist);
return isf_log_logistic(p, LL->alpha, LL->beta); return isf_log_logistic(p, LL->alpha, LL->beta);
} }
@ -1533,9 +1535,9 @@ const struct dist_ops_t log_logistic_ops = {
/** Functions for Weibull distribution */ /** Functions for Weibull distribution */
static double static double
weibull_sample(const struct dist *dist) weibull_sample(const struct dist_t *dist)
{ {
const struct weibull *W = dist_to_const_weibull(dist); const struct weibull_t *W = dist_to_const_weibull(dist);
uint32_t s = crypto_fast_rng_get_u32(get_thread_fast_rng()); uint32_t s = crypto_fast_rng_get_u32(get_thread_fast_rng());
double p0 = random_uniform_01(); double p0 = random_uniform_01();
@ -1543,30 +1545,30 @@ weibull_sample(const struct dist *dist)
} }
static double static double
weibull_cdf(const struct dist *dist, double x) weibull_cdf(const struct dist_t *dist, double x)
{ {
const struct weibull *W = dist_to_const_weibull(dist); const struct weibull_t *W = dist_to_const_weibull(dist);
return cdf_weibull(x, W->lambda, W->k); return cdf_weibull(x, W->lambda, W->k);
} }
static double static double
weibull_sf(const struct dist *dist, double x) weibull_sf(const struct dist_t *dist, double x)
{ {
const struct weibull *W = dist_to_const_weibull(dist); const struct weibull_t *W = dist_to_const_weibull(dist);
return sf_weibull(x, W->lambda, W->k); return sf_weibull(x, W->lambda, W->k);
} }
static double static double
weibull_icdf(const struct dist *dist, double p) weibull_icdf(const struct dist_t *dist, double p)
{ {
const struct weibull *W = dist_to_const_weibull(dist); const struct weibull_t *W = dist_to_const_weibull(dist);
return icdf_weibull(p, W->lambda, W->k); return icdf_weibull(p, W->lambda, W->k);
} }
static double static double
weibull_isf(const struct dist *dist, double p) weibull_isf(const struct dist_t *dist, double p)
{ {
const struct weibull *W = dist_to_const_weibull(dist); const struct weibull_t *W = dist_to_const_weibull(dist);
return isf_weibull(p, W->lambda, W->k); return isf_weibull(p, W->lambda, W->k);
} }
@ -1582,9 +1584,9 @@ const struct dist_ops_t weibull_ops = {
/** Functions for generalized Pareto distributions */ /** Functions for generalized Pareto distributions */
static double static double
genpareto_sample(const struct dist *dist) genpareto_sample(const struct dist_t *dist)
{ {
const struct genpareto *GP = dist_to_const_genpareto(dist); const struct genpareto_t *GP = dist_to_const_genpareto(dist);
uint32_t s = crypto_fast_rng_get_u32(get_thread_fast_rng()); uint32_t s = crypto_fast_rng_get_u32(get_thread_fast_rng());
double p0 = random_uniform_01(); double p0 = random_uniform_01();
@ -1592,30 +1594,30 @@ genpareto_sample(const struct dist *dist)
} }
static double static double
genpareto_cdf(const struct dist *dist, double x) genpareto_cdf(const struct dist_t *dist, double x)
{ {
const struct genpareto *GP = dist_to_const_genpareto(dist); const struct genpareto_t *GP = dist_to_const_genpareto(dist);
return cdf_genpareto(x, GP->mu, GP->sigma, GP->xi); return cdf_genpareto(x, GP->mu, GP->sigma, GP->xi);
} }
static double static double
genpareto_sf(const struct dist *dist, double x) genpareto_sf(const struct dist_t *dist, double x)
{ {
const struct genpareto *GP = dist_to_const_genpareto(dist); const struct genpareto_t *GP = dist_to_const_genpareto(dist);
return sf_genpareto(x, GP->mu, GP->sigma, GP->xi); return sf_genpareto(x, GP->mu, GP->sigma, GP->xi);
} }
static double static double
genpareto_icdf(const struct dist *dist, double p) genpareto_icdf(const struct dist_t *dist, double p)
{ {
const struct genpareto *GP = dist_to_const_genpareto(dist); const struct genpareto_t *GP = dist_to_const_genpareto(dist);
return icdf_genpareto(p, GP->mu, GP->sigma, GP->xi); return icdf_genpareto(p, GP->mu, GP->sigma, GP->xi);
} }
static double static double
genpareto_isf(const struct dist *dist, double p) genpareto_isf(const struct dist_t *dist, double p)
{ {
const struct genpareto *GP = dist_to_const_genpareto(dist); const struct genpareto_t *GP = dist_to_const_genpareto(dist);
return isf_genpareto(p, GP->mu, GP->sigma, GP->xi); return isf_genpareto(p, GP->mu, GP->sigma, GP->xi);
} }
@ -1631,9 +1633,9 @@ const struct dist_ops_t genpareto_ops = {
/** Functions for geometric distribution on number of trials before success */ /** Functions for geometric distribution on number of trials before success */
static double static double
geometric_sample(const struct dist *dist) geometric_sample(const struct dist_t *dist)
{ {
const struct geometric *G = dist_to_const_geometric(dist); const struct geometric_t *G = dist_to_const_geometric(dist);
uint32_t s = crypto_fast_rng_get_u32(get_thread_fast_rng()); uint32_t s = crypto_fast_rng_get_u32(get_thread_fast_rng());
double p0 = random_uniform_01(); double p0 = random_uniform_01();
@ -1641,9 +1643,9 @@ geometric_sample(const struct dist *dist)
} }
static double static double
geometric_cdf(const struct dist *dist, double x) geometric_cdf(const struct dist_t *dist, double x)
{ {
const struct geometric *G = dist_to_const_geometric(dist); const struct geometric_t *G = dist_to_const_geometric(dist);
if (x < 1) if (x < 1)
return 0; return 0;
@ -1652,9 +1654,9 @@ geometric_cdf(const struct dist *dist, double x)
} }
static double static double
geometric_sf(const struct dist *dist, double x) geometric_sf(const struct dist_t *dist, double x)
{ {
const struct geometric *G = dist_to_const_geometric(dist); const struct geometric_t *G = dist_to_const_geometric(dist);
if (x < 1) if (x < 1)
return 0; return 0;
@ -1663,17 +1665,17 @@ geometric_sf(const struct dist *dist, double x)
} }
static double static double
geometric_icdf(const struct dist *dist, double p) geometric_icdf(const struct dist_t *dist, double p)
{ {
const struct geometric *G = dist_to_const_geometric(dist); const struct geometric_t *G = dist_to_const_geometric(dist);
return log1p(-p)/log1p(-G->p); return log1p(-p)/log1p(-G->p);
} }
static double static double
geometric_isf(const struct dist *dist, double p) geometric_isf(const struct dist_t *dist, double p)
{ {
const struct geometric *G = dist_to_const_geometric(dist); const struct geometric_t *G = dist_to_const_geometric(dist);
return log(p)/log1p(-G->p); return log(p)/log1p(-G->p);
} }

View File

@ -15,12 +15,12 @@
/** /**
* Container for distribution parameters for sampling, CDF, &c. * Container for distribution parameters for sampling, CDF, &c.
*/ */
struct dist { struct dist_t {
const struct dist_ops_t *ops; const struct dist_ops_t *ops;
}; };
/** /**
* Untyped initializer element for struct dist using the specified * Untyped initializer element for struct dist_t using the specified
* struct dist_ops_t pointer. Don't actually use this directly -- use * struct dist_ops_t pointer. Don't actually use this directly -- use
* the type-specific macro built out of DIST_BASE_TYPED below -- but if * the type-specific macro built out of DIST_BASE_TYPED below -- but if
* you did use this directly, it would be something like: * you did use this directly, it would be something like:
@ -61,13 +61,13 @@ struct dist {
#endif /* defined(__COVERITY__) */ #endif /* defined(__COVERITY__) */
/** /**
* Typed initializer element for struct dist using the specified struct * Typed initializer element for struct dist_t using the specified struct
* dist_ops_t pointer. Don't actually use this directly -- use a * dist_ops_t pointer. Don't actually use this directly -- use a
* type-specific macro built out of it -- but if you did use this * type-specific macro built out of it -- but if you did use this
* directly, it would be something like: * directly, it would be something like:
* *
* struct weibull mydist = { * struct weibull mydist = {
* DIST_BASE_TYPED(&weibull_ops, mydist, struct weibull), * DIST_BASE_TYPED(&weibull_ops, mydist, struct weibull_t),
* .lambda = ..., * .lambda = ...,
* .k = ..., * .k = ...,
* }; * };
@ -76,7 +76,7 @@ struct dist {
* operations and define a type-specific initializer element like so: * operations and define a type-specific initializer element like so:
* *
* struct foo { * struct foo {
* struct dist base; * struct dist_t base;
* int omega; * int omega;
* double tau; * double tau;
* double phi; * double phi;
@ -113,12 +113,12 @@ struct dist {
* corresponding dist_ops_t function. In the parlance of C++, these call * corresponding dist_ops_t function. In the parlance of C++, these call
* virtual member functions. * virtual member functions.
*/ */
const char *dist_name(const struct dist *); const char *dist_name(const struct dist_t *);
double dist_sample(const struct dist *); double dist_sample(const struct dist_t *);
double dist_cdf(const struct dist *, double x); double dist_cdf(const struct dist_t *, double x);
double dist_sf(const struct dist *, double x); double dist_sf(const struct dist_t *, double x);
double dist_icdf(const struct dist *, double p); double dist_icdf(const struct dist_t *, double p);
double dist_isf(const struct dist *, double p); double dist_isf(const struct dist_t *, double p);
/** /**
* Set of operations on a potentially parametric family of * Set of operations on a potentially parametric family of
@ -127,29 +127,29 @@ double dist_isf(const struct dist *, double p);
*/ */
struct dist_ops_t { struct dist_ops_t {
const char *name; const char *name;
double (*sample)(const struct dist *); double (*sample)(const struct dist_t *);
double (*cdf)(const struct dist *, double x); double (*cdf)(const struct dist_t *, double x);
double (*sf)(const struct dist *, double x); double (*sf)(const struct dist_t *, double x);
double (*icdf)(const struct dist *, double p); double (*icdf)(const struct dist_t *, double p);
double (*isf)(const struct dist *, double p); double (*isf)(const struct dist_t *, double p);
}; };
/* Geometric distribution on positive number of trials before first success */ /* Geometric distribution on positive number of trials before first success */
struct geometric { struct geometric_t {
struct dist base; struct dist_t base;
double p; /* success probability */ double p; /* success probability */
}; };
extern const struct dist_ops_t geometric_ops; extern const struct dist_ops_t geometric_ops;
#define GEOMETRIC(OBJ) \ #define GEOMETRIC(OBJ) \
DIST_BASE_TYPED(&geometric_ops, OBJ, struct geometric) DIST_BASE_TYPED(&geometric_ops, OBJ, struct geometric_t)
/* Pareto distribution */ /* Pareto distribution */
struct genpareto { struct genpareto_t {
struct dist base; struct dist_t base;
double mu; double mu;
double sigma; double sigma;
double xi; double xi;
@ -158,12 +158,12 @@ struct genpareto {
extern const struct dist_ops_t genpareto_ops; extern const struct dist_ops_t genpareto_ops;
#define GENPARETO(OBJ) \ #define GENPARETO(OBJ) \
DIST_BASE_TYPED(&genpareto_ops, OBJ, struct genpareto) DIST_BASE_TYPED(&genpareto_ops, OBJ, struct genpareto_t)
/* Weibull distribution */ /* Weibull distribution */
struct weibull { struct weibull_t {
struct dist base; struct dist_t base;
double lambda; double lambda;
double k; double k;
}; };
@ -171,12 +171,12 @@ struct weibull {
extern const struct dist_ops_t weibull_ops; extern const struct dist_ops_t weibull_ops;
#define WEIBULL(OBJ) \ #define WEIBULL(OBJ) \
DIST_BASE_TYPED(&weibull_ops, OBJ, struct weibull) DIST_BASE_TYPED(&weibull_ops, OBJ, struct weibull_t)
/* Log-logistic distribution */ /* Log-logistic distribution */
struct log_logistic { struct log_logistic_t {
struct dist base; struct dist_t base;
double alpha; double alpha;
double beta; double beta;
}; };
@ -184,12 +184,12 @@ struct log_logistic {
extern const struct dist_ops_t log_logistic_ops; extern const struct dist_ops_t log_logistic_ops;
#define LOG_LOGISTIC(OBJ) \ #define LOG_LOGISTIC(OBJ) \
DIST_BASE_TYPED(&log_logistic_ops, OBJ, struct log_logistic) DIST_BASE_TYPED(&log_logistic_ops, OBJ, struct log_logistic_t)
/* Logistic distribution */ /* Logistic distribution */
struct logistic { struct logistic_t {
struct dist base; struct dist_t base;
double mu; double mu;
double sigma; double sigma;
}; };
@ -197,12 +197,12 @@ struct logistic {
extern const struct dist_ops_t logistic_ops; extern const struct dist_ops_t logistic_ops;
#define LOGISTIC(OBJ) \ #define LOGISTIC(OBJ) \
DIST_BASE_TYPED(&logistic_ops, OBJ, struct logistic) DIST_BASE_TYPED(&logistic_ops, OBJ, struct logistic_t)
/* Uniform distribution */ /* Uniform distribution */
struct uniform { struct uniform_t {
struct dist base; struct dist_t base;
double a; double a;
double b; double b;
}; };
@ -210,7 +210,7 @@ struct uniform {
extern const struct dist_ops_t uniform_ops; extern const struct dist_ops_t uniform_ops;
#define UNIFORM(OBJ) \ #define UNIFORM(OBJ) \
DIST_BASE_TYPED(&uniform_ops, OBJ, struct uniform) DIST_BASE_TYPED(&uniform_ops, OBJ, struct uniform_t)
/** Only by unittests */ /** Only by unittests */

View File

@ -946,7 +946,7 @@ psi_test(const size_t C[PSI_DF], const double logP[PSI_DF], size_t N)
static bool static bool
test_stochastic_geometric_impl(double p) test_stochastic_geometric_impl(double p)
{ {
const struct geometric geometric = { const struct geometric_t geometric = {
.base = GEOMETRIC(geometric), .base = GEOMETRIC(geometric),
.p = p, .p = p,
}; };
@ -1012,7 +1012,8 @@ test_stochastic_geometric_impl(double p)
* +inf, and x_i = i*(hi - lo)/(n - 2). * +inf, and x_i = i*(hi - lo)/(n - 2).
*/ */
static void static void
bin_cdfs(const struct dist *dist, double lo, double hi, double *logP, size_t n) bin_cdfs(const struct dist_t *dist, double lo, double hi, double *logP,
size_t n)
{ {
#define CDF(x) dist_cdf(dist, x) #define CDF(x) dist_cdf(dist, x)
#define SF(x) dist_sf(dist, x) #define SF(x) dist_sf(dist, x)
@ -1059,7 +1060,8 @@ bin_cdfs(const struct dist *dist, double lo, double hi, double *logP, size_t n)
* +inf, and x_i = i*(hi - lo)/(n - 2). * +inf, and x_i = i*(hi - lo)/(n - 2).
*/ */
static void static void
bin_samples(const struct dist *dist, double lo, double hi, size_t *C, size_t n) bin_samples(const struct dist_t *dist, double lo, double hi, size_t *C,
size_t n)
{ {
const double w = (hi - lo)/(n - 2); const double w = (hi - lo)/(n - 2);
size_t i; size_t i;
@ -1088,7 +1090,7 @@ bin_samples(const struct dist *dist, double lo, double hi, size_t *C, size_t n)
* 0.01^2 = 0.0001. * 0.01^2 = 0.0001.
*/ */
static bool static bool
test_psi_dist_sample(const struct dist *dist) test_psi_dist_sample(const struct dist_t *dist)
{ {
double logP[PSI_DF] = {0}; double logP[PSI_DF] = {0};
unsigned ntry = NTRIALS, npass = 0; unsigned ntry = NTRIALS, npass = 0;
@ -1134,32 +1136,32 @@ test_stochastic_uniform(void *arg)
{ {
(void) arg; (void) arg;
const struct uniform uniform01 = { const struct uniform_t uniform01 = {
.base = UNIFORM(uniform01), .base = UNIFORM(uniform01),
.a = 0, .a = 0,
.b = 1, .b = 1,
}; };
const struct uniform uniform_pos = { const struct uniform_t uniform_pos = {
.base = UNIFORM(uniform_pos), .base = UNIFORM(uniform_pos),
.a = 1.23, .a = 1.23,
.b = 4.56, .b = 4.56,
}; };
const struct uniform uniform_neg = { const struct uniform_t uniform_neg = {
.base = UNIFORM(uniform_neg), .base = UNIFORM(uniform_neg),
.a = -10, .a = -10,
.b = -1, .b = -1,
}; };
const struct uniform uniform_cross = { const struct uniform_t uniform_cross = {
.base = UNIFORM(uniform_cross), .base = UNIFORM(uniform_cross),
.a = -1.23, .a = -1.23,
.b = 4.56, .b = 4.56,
}; };
const struct uniform uniform_subnormal = { const struct uniform_t uniform_subnormal = {
.base = UNIFORM(uniform_subnormal), .base = UNIFORM(uniform_subnormal),
.a = 4e-324, .a = 4e-324,
.b = 4e-310, .b = 4e-310,
}; };
const struct uniform uniform_subnormal_cross = { const struct uniform_t uniform_subnormal_cross = {
.base = UNIFORM(uniform_subnormal_cross), .base = UNIFORM(uniform_subnormal_cross),
.a = -4e-324, .a = -4e-324,
.b = 4e-310, .b = 4e-310,
@ -1189,7 +1191,7 @@ test_stochastic_uniform(void *arg)
static bool static bool
test_stochastic_logistic_impl(double mu, double sigma) test_stochastic_logistic_impl(double mu, double sigma)
{ {
const struct logistic dist = { const struct logistic_t dist = {
.base = LOGISTIC(dist), .base = LOGISTIC(dist),
.mu = mu, .mu = mu,
.sigma = sigma, .sigma = sigma,
@ -1202,7 +1204,7 @@ test_stochastic_logistic_impl(double mu, double sigma)
static bool static bool
test_stochastic_log_logistic_impl(double alpha, double beta) test_stochastic_log_logistic_impl(double alpha, double beta)
{ {
const struct log_logistic dist = { const struct log_logistic_t dist = {
.base = LOG_LOGISTIC(dist), .base = LOG_LOGISTIC(dist),
.alpha = alpha, .alpha = alpha,
.beta = beta, .beta = beta,
@ -1215,7 +1217,7 @@ test_stochastic_log_logistic_impl(double alpha, double beta)
static bool static bool
test_stochastic_weibull_impl(double lambda, double k) test_stochastic_weibull_impl(double lambda, double k)
{ {
const struct weibull dist = { const struct weibull_t dist = {
.base = WEIBULL(dist), .base = WEIBULL(dist),
.lambda = lambda, .lambda = lambda,
.k = k, .k = k,
@ -1235,7 +1237,7 @@ test_stochastic_weibull_impl(double lambda, double k)
static bool static bool
test_stochastic_genpareto_impl(double mu, double sigma, double xi) test_stochastic_genpareto_impl(double mu, double sigma, double xi)
{ {
const struct genpareto dist = { const struct genpareto_t dist = {
.base = GENPARETO(dist), .base = GENPARETO(dist),
.mu = mu, .mu = mu,
.sigma = sigma, .sigma = sigma,