Loading src/core/or/circuitpadding.c +6 −6 Original line number Diff line number Diff line Loading @@ -541,7 +541,7 @@ circpad_distribution_sample(circpad_distribution_t dist) { // param2 is upper bound, param1 is lower const struct uniform my_uniform = { .base = DIST_BASE(&uniform_ops), .base = UNIFORM(my_uniform), .a = dist.param1, .b = dist.param2, }; Loading @@ -551,7 +551,7 @@ circpad_distribution_sample(circpad_distribution_t dist) { /* param1 is Mu, param2 is sigma. */ const struct logistic my_logistic = { .base = DIST_BASE(&uniform_ops), .base = LOGISTIC(my_uniform), .mu = dist.param1, .sigma = dist.param2, }; Loading @@ -561,7 +561,7 @@ circpad_distribution_sample(circpad_distribution_t dist) { /* param1 is Alpha, param2 is 1.0/Beta */ const struct log_logistic my_log_logistic = { .base = DIST_BASE(&log_logistic_ops), .base = LOG_LOGISTIC(my_log_logistic), .alpha = dist.param1, .beta = dist.param2, }; Loading @@ -571,7 +571,7 @@ circpad_distribution_sample(circpad_distribution_t dist) { /* param1 is 'p' (success probability) */ const struct geometric my_geometric = { .base = DIST_BASE(&geometric_ops), .base = GEOMETRIC(my_geometric), .p = dist.param1, }; return dist_sample(&my_geometric.base); Loading @@ -580,7 +580,7 @@ circpad_distribution_sample(circpad_distribution_t dist) { /* param1 is k, param2 is Lambda */ const struct weibull my_weibull = { .base = DIST_BASE(&weibull_ops), .base = WEIBULL(my_weibull), .k = dist.param1, .lambda = dist.param2, }; Loading @@ -590,7 +590,7 @@ circpad_distribution_sample(circpad_distribution_t dist) { /* param1 is sigma, param2 is xi, no more params for mu so we use 0 */ const struct genpareto my_genpareto = { .base = DIST_BASE(&weibull_ops), .base = GENPARETO(my_weibull), .mu = 0, .sigma = dist.param1, .xi = dist.param2, Loading src/lib/math/prob_distr.h +20 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ struct dist { }; #define DIST_BASE(OPS) { .ops = (OPS) } #define DIST_BASE_TYPED(OPS, OBJ, TYPE) \ DIST_BASE((OPS) + 0*sizeof(&(OBJ) - (const TYPE *)&(OBJ))) const char *dist_name(const struct dist *); double dist_sample(const struct dist *); Loading @@ -46,6 +48,9 @@ struct geometric { extern const struct dist_ops geometric_ops; #define GEOMETRIC(OBJ) \ DIST_BASE_TYPED(&geometric_ops, OBJ, struct geometric) /* Pareto distribution */ struct genpareto { Loading @@ -57,6 +62,9 @@ struct genpareto { extern const struct dist_ops genpareto_ops; #define GENPARETO(OBJ) \ DIST_BASE_TYPED(&genpareto_ops, OBJ, struct genpareto) /* Weibull distribution */ struct weibull { Loading @@ -67,6 +75,9 @@ struct weibull { extern const struct dist_ops weibull_ops; #define WEIBULL(OBJ) \ DIST_BASE_TYPED(&weibull_ops, OBJ, struct weibull) /* Log-logistic distribution */ struct log_logistic { Loading @@ -77,6 +88,9 @@ struct log_logistic { extern const struct dist_ops log_logistic_ops; #define LOG_LOGISTIC(OBJ) \ DIST_BASE_TYPED(&log_logistic_ops, OBJ, struct log_logistic) /* Logistic distribution */ struct logistic { Loading @@ -87,6 +101,9 @@ struct logistic { extern const struct dist_ops logistic_ops; #define LOGISTIC(OBJ) \ DIST_BASE_TYPED(&logistic_ops, OBJ, struct logistic) /* Uniform distribution */ struct uniform { Loading @@ -97,6 +114,9 @@ struct uniform { extern const struct dist_ops uniform_ops; #define UNIFORM(OBJ) \ DIST_BASE_TYPED(&uniform_ops, OBJ, struct uniform) /** Only by unittests */ #ifdef PROB_DISTR_PRIVATE Loading src/test/test_prob_distr.c +11 −11 Original line number Diff line number Diff line Loading @@ -943,7 +943,7 @@ static bool test_stochastic_geometric_impl(double p) { const struct geometric geometric = { .base = DIST_BASE(&geometric_ops), .base = GEOMETRIC(geometric), .p = p, }; double logP[PSI_DF] = {0}; Loading Loading @@ -1151,32 +1151,32 @@ test_stochastic_uniform(void *arg) (void) arg; const struct uniform uniform01 = { .base = DIST_BASE(&uniform_ops), .base = UNIFORM(uniform01), .a = 0, .b = 1, }; const struct uniform uniform_pos = { .base = DIST_BASE(&uniform_ops), .base = UNIFORM(uniform_pos), .a = 1.23, .b = 4.56, }; const struct uniform uniform_neg = { .base = DIST_BASE(&uniform_ops), .base = UNIFORM(uniform_neg), .a = -10, .b = -1, }; const struct uniform uniform_cross = { .base = DIST_BASE(&uniform_ops), .base = UNIFORM(uniform_cross), .a = -1.23, .b = 4.56, }; const struct uniform uniform_subnormal = { .base = DIST_BASE(&uniform_ops), .base = UNIFORM(uniform_subnormal), .a = 4e-324, .b = 4e-310, }; const struct uniform uniform_subnormal_cross = { .base = DIST_BASE(&uniform_ops), .base = UNIFORM(uniform_subnormal_cross), .a = -4e-324, .b = 4e-310, }; Loading @@ -1202,7 +1202,7 @@ static bool test_stochastic_logistic_impl(double mu, double sigma) { const struct logistic dist = { .base = DIST_BASE(&logistic_ops), .base = LOGISTIC(dist), .mu = mu, .sigma = sigma, }; Loading @@ -1215,7 +1215,7 @@ static bool test_stochastic_log_logistic_impl(double alpha, double beta) { const struct log_logistic dist = { .base = DIST_BASE(&log_logistic_ops), .base = LOG_LOGISTIC(dist), .alpha = alpha, .beta = beta, }; Loading @@ -1228,7 +1228,7 @@ static bool test_stochastic_weibull_impl(double lambda, double k) { const struct weibull dist = { .base = DIST_BASE(&weibull_ops), .base = WEIBULL(dist), .lambda = lambda, .k = k, }; Loading @@ -1248,7 +1248,7 @@ static bool test_stochastic_genpareto_impl(double mu, double sigma, double xi) { const struct genpareto dist = { .base = DIST_BASE(&genpareto_ops), .base = GENPARETO(dist), .mu = mu, .sigma = sigma, .xi = xi, Loading Loading
src/core/or/circuitpadding.c +6 −6 Original line number Diff line number Diff line Loading @@ -541,7 +541,7 @@ circpad_distribution_sample(circpad_distribution_t dist) { // param2 is upper bound, param1 is lower const struct uniform my_uniform = { .base = DIST_BASE(&uniform_ops), .base = UNIFORM(my_uniform), .a = dist.param1, .b = dist.param2, }; Loading @@ -551,7 +551,7 @@ circpad_distribution_sample(circpad_distribution_t dist) { /* param1 is Mu, param2 is sigma. */ const struct logistic my_logistic = { .base = DIST_BASE(&uniform_ops), .base = LOGISTIC(my_uniform), .mu = dist.param1, .sigma = dist.param2, }; Loading @@ -561,7 +561,7 @@ circpad_distribution_sample(circpad_distribution_t dist) { /* param1 is Alpha, param2 is 1.0/Beta */ const struct log_logistic my_log_logistic = { .base = DIST_BASE(&log_logistic_ops), .base = LOG_LOGISTIC(my_log_logistic), .alpha = dist.param1, .beta = dist.param2, }; Loading @@ -571,7 +571,7 @@ circpad_distribution_sample(circpad_distribution_t dist) { /* param1 is 'p' (success probability) */ const struct geometric my_geometric = { .base = DIST_BASE(&geometric_ops), .base = GEOMETRIC(my_geometric), .p = dist.param1, }; return dist_sample(&my_geometric.base); Loading @@ -580,7 +580,7 @@ circpad_distribution_sample(circpad_distribution_t dist) { /* param1 is k, param2 is Lambda */ const struct weibull my_weibull = { .base = DIST_BASE(&weibull_ops), .base = WEIBULL(my_weibull), .k = dist.param1, .lambda = dist.param2, }; Loading @@ -590,7 +590,7 @@ circpad_distribution_sample(circpad_distribution_t dist) { /* param1 is sigma, param2 is xi, no more params for mu so we use 0 */ const struct genpareto my_genpareto = { .base = DIST_BASE(&weibull_ops), .base = GENPARETO(my_weibull), .mu = 0, .sigma = dist.param1, .xi = dist.param2, Loading
src/lib/math/prob_distr.h +20 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,8 @@ struct dist { }; #define DIST_BASE(OPS) { .ops = (OPS) } #define DIST_BASE_TYPED(OPS, OBJ, TYPE) \ DIST_BASE((OPS) + 0*sizeof(&(OBJ) - (const TYPE *)&(OBJ))) const char *dist_name(const struct dist *); double dist_sample(const struct dist *); Loading @@ -46,6 +48,9 @@ struct geometric { extern const struct dist_ops geometric_ops; #define GEOMETRIC(OBJ) \ DIST_BASE_TYPED(&geometric_ops, OBJ, struct geometric) /* Pareto distribution */ struct genpareto { Loading @@ -57,6 +62,9 @@ struct genpareto { extern const struct dist_ops genpareto_ops; #define GENPARETO(OBJ) \ DIST_BASE_TYPED(&genpareto_ops, OBJ, struct genpareto) /* Weibull distribution */ struct weibull { Loading @@ -67,6 +75,9 @@ struct weibull { extern const struct dist_ops weibull_ops; #define WEIBULL(OBJ) \ DIST_BASE_TYPED(&weibull_ops, OBJ, struct weibull) /* Log-logistic distribution */ struct log_logistic { Loading @@ -77,6 +88,9 @@ struct log_logistic { extern const struct dist_ops log_logistic_ops; #define LOG_LOGISTIC(OBJ) \ DIST_BASE_TYPED(&log_logistic_ops, OBJ, struct log_logistic) /* Logistic distribution */ struct logistic { Loading @@ -87,6 +101,9 @@ struct logistic { extern const struct dist_ops logistic_ops; #define LOGISTIC(OBJ) \ DIST_BASE_TYPED(&logistic_ops, OBJ, struct logistic) /* Uniform distribution */ struct uniform { Loading @@ -97,6 +114,9 @@ struct uniform { extern const struct dist_ops uniform_ops; #define UNIFORM(OBJ) \ DIST_BASE_TYPED(&uniform_ops, OBJ, struct uniform) /** Only by unittests */ #ifdef PROB_DISTR_PRIVATE Loading
src/test/test_prob_distr.c +11 −11 Original line number Diff line number Diff line Loading @@ -943,7 +943,7 @@ static bool test_stochastic_geometric_impl(double p) { const struct geometric geometric = { .base = DIST_BASE(&geometric_ops), .base = GEOMETRIC(geometric), .p = p, }; double logP[PSI_DF] = {0}; Loading Loading @@ -1151,32 +1151,32 @@ test_stochastic_uniform(void *arg) (void) arg; const struct uniform uniform01 = { .base = DIST_BASE(&uniform_ops), .base = UNIFORM(uniform01), .a = 0, .b = 1, }; const struct uniform uniform_pos = { .base = DIST_BASE(&uniform_ops), .base = UNIFORM(uniform_pos), .a = 1.23, .b = 4.56, }; const struct uniform uniform_neg = { .base = DIST_BASE(&uniform_ops), .base = UNIFORM(uniform_neg), .a = -10, .b = -1, }; const struct uniform uniform_cross = { .base = DIST_BASE(&uniform_ops), .base = UNIFORM(uniform_cross), .a = -1.23, .b = 4.56, }; const struct uniform uniform_subnormal = { .base = DIST_BASE(&uniform_ops), .base = UNIFORM(uniform_subnormal), .a = 4e-324, .b = 4e-310, }; const struct uniform uniform_subnormal_cross = { .base = DIST_BASE(&uniform_ops), .base = UNIFORM(uniform_subnormal_cross), .a = -4e-324, .b = 4e-310, }; Loading @@ -1202,7 +1202,7 @@ static bool test_stochastic_logistic_impl(double mu, double sigma) { const struct logistic dist = { .base = DIST_BASE(&logistic_ops), .base = LOGISTIC(dist), .mu = mu, .sigma = sigma, }; Loading @@ -1215,7 +1215,7 @@ static bool test_stochastic_log_logistic_impl(double alpha, double beta) { const struct log_logistic dist = { .base = DIST_BASE(&log_logistic_ops), .base = LOG_LOGISTIC(dist), .alpha = alpha, .beta = beta, }; Loading @@ -1228,7 +1228,7 @@ static bool test_stochastic_weibull_impl(double lambda, double k) { const struct weibull dist = { .base = DIST_BASE(&weibull_ops), .base = WEIBULL(dist), .lambda = lambda, .k = k, }; Loading @@ -1248,7 +1248,7 @@ static bool test_stochastic_genpareto_impl(double mu, double sigma, double xi) { const struct genpareto dist = { .base = DIST_BASE(&genpareto_ops), .base = GENPARETO(dist), .mu = mu, .sigma = sigma, .xi = xi, Loading