commit 952521287a20346a6ba8404aab152b21c80ec203
parent 9eb9c4280f89c2d96080229b8082a816ac3faf7e
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 5 Oct 2016 16:32:06 +0200
Relax test constraints on Gaussian & Piecewise linear distributions
Test failed on CL compiler.
Minor refactoring to make consistent the coding style.
Diffstat:
2 files changed, 35 insertions(+), 36 deletions(-)
diff --git a/src/test_ssp_ran_gaussian.c b/src/test_ssp_ran_gaussian.c
@@ -37,7 +37,6 @@
int
main(int argc, char** argv)
{
- struct ssp_rng_proxy* proxy;
struct ssp_rng* rng;
struct mem_allocator allocator;
struct ssp_ranst_gaussian *gaussian;
@@ -51,8 +50,7 @@ main(int argc, char** argv)
mem_init_proxy_allocator(&allocator, &mem_default_allocator);
- CHECK(ssp_rng_proxy_create(&allocator, &ssp_rng_threefry, 1, &proxy), RES_OK);
- CHECK(ssp_rng_proxy_create_rng(proxy, 0, &rng), RES_OK);
+ CHECK(ssp_rng_create(&allocator, &ssp_rng_mt19937_64, &rng), RES_OK);
CHECK(ssp_ranst_gaussian_create(NULL, NULL), RES_BAD_ARG);
CHECK(ssp_ranst_gaussian_create(NULL, &gaussian), RES_OK);
@@ -72,10 +70,10 @@ main(int argc, char** argv)
CHECK(ssp_ranst_gaussian_ref_put(gaussian), RES_OK);
time_current(&start);
- for (i = 0; i < NBS; i++) {
- double _x = ssp_ranst_gaussian_get(gaussian, rng);
- x += _x;
- x2 += _x * _x;
+ FOR_EACH(i, 0, NBS) {
+ const double r = ssp_ranst_gaussian_get(gaussian, rng);
+ x += r;
+ x2 += r * r;
}
time_current(&end);
time_sub(&res, &end, &start);
@@ -83,20 +81,20 @@ main(int argc, char** argv)
printf("%s--\n", dump);
mean = x/NBS;
- std = sqrt(x2/NBS - x/NBS*x/NBS);
+ std = sqrt(x2/NBS - mean*mean);
printf("%g %g\n", mean, std);
- CHECK(fabs(mean - exp_mean) < 0.003, 1);
- CHECK(fabs(std - exp_std) < 0.001, 1);
+ CHECK(eq_eps(mean, exp_mean, 1e-2), 1);
+ CHECK(eq_eps(std, exp_std, 1e-2), 1);
- /* same test with inline gaussian generation */
+ /* Same test with inline gaussian generation */
x = 0;
x2 = 0;
time_current(&start);
- for (i = 0; i < NBS; i++) {
- double _x = ssp_ran_gaussian(rng, exp_mean, exp_std);
- x += _x;
- x2 += _x * _x;
+ FOR_EACH(i, 0, NBS) {
+ const double r = ssp_ran_gaussian(rng, exp_mean, exp_std);
+ x += r;
+ x2 += r * r;
}
time_current(&end);
time_sub(&res, &end, &start);
@@ -104,15 +102,14 @@ main(int argc, char** argv)
printf("%s--\n", dump);
mean = x/NBS;
- std = sqrt(x2/NBS - x/NBS*x/NBS);
+ std = sqrt(x2/NBS - mean*mean);
printf("%g %g\n", mean, std);
- CHECK(fabs(mean - exp_mean) < 0.003, 1);
- CHECK(fabs(std - exp_std) < 0.001, 1);
+ CHECK(eq_eps(mean, exp_mean, 1.e-2), 1);
+ CHECK(eq_eps(std, exp_std, 1e-2), 1);
CHECK(ssp_ranst_gaussian_ref_put(gaussian), RES_OK);
CHECK(ssp_rng_ref_put(rng), RES_OK);
- CHECK(ssp_rng_proxy_ref_put(proxy), RES_OK);
check_memory_allocator(&allocator);
mem_shutdown_proxy_allocator(&allocator);
diff --git a/src/test_ssp_ran_piecewise_linear.c b/src/test_ssp_ran_piecewise_linear.c
@@ -36,7 +36,6 @@
int
main(int argc, char** argv)
{
- struct ssp_rng_proxy* proxy;
struct ssp_rng* rng;
struct mem_allocator allocator;
struct ssp_ranst_piecewise_linear *pwl;
@@ -50,8 +49,7 @@ main(int argc, char** argv)
mem_init_proxy_allocator(&allocator, &mem_default_allocator);
- CHECK(ssp_rng_proxy_create(&allocator, &ssp_rng_threefry, 1, &proxy), RES_OK);
- CHECK(ssp_rng_proxy_create_rng(proxy, 0, &rng), RES_OK);
+ CHECK(ssp_rng_create(&allocator, &ssp_rng_mt19937_64, &rng), RES_OK);
CHECK(ssp_ranst_piecewise_linear_create(NULL, NULL), RES_BAD_ARG);
CHECK(ssp_ranst_piecewise_linear_create(NULL, &pwl), RES_OK);
@@ -60,11 +58,16 @@ main(int argc, char** argv)
CHECK(ssp_ranst_piecewise_linear_create(&allocator, NULL), RES_BAD_ARG);
CHECK(ssp_ranst_piecewise_linear_create(&allocator, &pwl), RES_OK);
- CHECK(ssp_ranst_piecewise_linear_setup(NULL, intervals, weights, sizeof(intervals)/sizeof(double)), RES_BAD_ARG);
- CHECK(ssp_ranst_piecewise_linear_setup(pwl, NULL, weights, sizeof(intervals)/sizeof(double)), RES_BAD_ARG);
- CHECK(ssp_ranst_piecewise_linear_setup(pwl, intervals, NULL, sizeof(intervals)/sizeof(double)), RES_BAD_ARG);
- CHECK(ssp_ranst_piecewise_linear_setup(pwl, intervals, weights, 1), RES_BAD_ARG);
- CHECK(ssp_ranst_piecewise_linear_setup(pwl, intervals, weights, sizeof(intervals)/sizeof(double)), RES_OK);
+ CHECK(ssp_ranst_piecewise_linear_setup
+ (NULL, intervals, weights, sizeof(intervals)/sizeof(double)), RES_BAD_ARG);
+ CHECK(ssp_ranst_piecewise_linear_setup
+ (pwl, NULL, weights, sizeof(intervals)/sizeof(double)), RES_BAD_ARG);
+ CHECK(ssp_ranst_piecewise_linear_setup
+ (pwl, intervals, NULL, sizeof(intervals)/sizeof(double)), RES_BAD_ARG);
+ CHECK(ssp_ranst_piecewise_linear_setup
+ (pwl, intervals, weights, 1), RES_BAD_ARG);
+ CHECK(ssp_ranst_piecewise_linear_setup
+ (pwl, intervals, weights, sizeof(intervals)/sizeof(double)), RES_OK);
CHECK(ssp_ranst_piecewise_linear_ref_get(NULL), RES_BAD_ARG);
CHECK(ssp_ranst_piecewise_linear_ref_get(pwl), RES_OK);
@@ -72,23 +75,22 @@ main(int argc, char** argv)
CHECK(ssp_ranst_piecewise_linear_ref_put(NULL), RES_BAD_ARG);
CHECK(ssp_ranst_piecewise_linear_ref_put(pwl), RES_OK);
- for (i = 0; i < NBS; i++) {
- double _x = ssp_ranst_piecewise_linear_get(pwl, rng);
- CHECK(0 <= _x && _x <= 10, 1);
- x += _x;
- x2 += _x * _x;
+ FOR_EACH(i, 0, NBS) {
+ double r = ssp_ranst_piecewise_linear_get(pwl, rng);
+ CHECK(0 <= r && r <= 10, 1);
+ x += r;
+ x2 += r * r;
}
mean = x/NBS;
- std = sqrt(x2/NBS - x/NBS*x/NBS);
+ std = sqrt(x2/NBS - mean*mean);
printf("%g %g\n", mean, std);
- CHECK(fabs(mean - exp_mean) < 0.001, 1);
- CHECK(fabs(std - exp_std) < 0.001, 1);
+ CHECK(eq_eps(mean, exp_mean, 1e-2), 1);
+ CHECK(eq_eps(std, exp_std, 1.e-2), 1);
CHECK(ssp_ranst_piecewise_linear_ref_put(pwl), RES_OK);
CHECK(ssp_rng_ref_put(rng), RES_OK);
- CHECK(ssp_rng_proxy_ref_put(proxy), RES_OK);
check_memory_allocator(&allocator);
mem_shutdown_proxy_allocator(&allocator);