star-sp

Random number generators and distributions
git clone git://git.meso-star.fr/star-sp.git
Log | Files | Refs | README | LICENSE

commit 61de7b92c788bd5549c8be4655327df5ba42d134
parent f84f6f5e88ab839ceec70c493fe6f404a307633f
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue, 15 Jun 2021 16:55:42 +0200

Merge branch 'release_0.10'

Diffstat:
MREADME.md | 6+++++-
Mcmake/CMakeLists.txt | 4++--
Msrc/ssp.h | 31++++++++++++++++++++++++++++---
Msrc/ssp_ran.c | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------
Msrc/ssp_ranst_discrete.c | 2+-
Msrc/ssp_ranst_gaussian.c | 2+-
Msrc/ssp_ranst_piecewise_linear.c | 2+-
Msrc/ssp_rng.c | 63++++++++++++++++++++++++++++++++++++++++++---------------------
Msrc/ssp_rng_c.h | 2+-
Msrc/ssp_rng_proxy.c | 2+-
Msrc/test_ssp_ran_circle.c | 2+-
Msrc/test_ssp_ran_circle.h | 2+-
Msrc/test_ssp_ran_discrete.c | 2+-
Msrc/test_ssp_ran_discrete.h | 2+-
Msrc/test_ssp_ran_gaussian.c | 2+-
Msrc/test_ssp_ran_gaussian.h | 2+-
Msrc/test_ssp_ran_hemisphere.c | 2+-
Msrc/test_ssp_ran_hemisphere.h | 2+-
Msrc/test_ssp_ran_hg.c | 2+-
Msrc/test_ssp_ran_hg.h | 2+-
Msrc/test_ssp_ran_piecewise_linear.c | 2+-
Msrc/test_ssp_ran_piecewise_linear.h | 2+-
Msrc/test_ssp_ran_sphere.c | 2+-
Msrc/test_ssp_ran_sphere.h | 2+-
Msrc/test_ssp_ran_sphere_cap.c | 2+-
Msrc/test_ssp_ran_sphere_cap.h | 2+-
Msrc/test_ssp_ran_tetrahedron.c | 2+-
Msrc/test_ssp_ran_tetrahedron.h | 2+-
Msrc/test_ssp_ran_triangle.c | 2+-
Msrc/test_ssp_ran_triangle.h | 2+-
Msrc/test_ssp_ran_uniform_disk.c | 2+-
Msrc/test_ssp_ran_uniform_disk.h | 2+-
Msrc/test_ssp_rng.c | 9++++++---
Msrc/test_ssp_rng.h | 2+-
Msrc/test_ssp_rng_proxy.c | 2+-
Msrc/test_ssp_rng_proxy.h | 2+-
Msrc/test_ssp_utils.h | 2+-
37 files changed, 180 insertions(+), 83 deletions(-)

diff --git a/README.md b/README.md @@ -34,6 +34,10 @@ variable to the directory that contains the `boost` include directory. ## Release notes +### Version 0.10 + +- Add the `ssp_ran_exp_truncated` random variates. + ### Version 0.9 - Rewrite the caching mechanism used to register the RNG states provided by the @@ -103,7 +107,7 @@ variable to the directory that contains the `boost` include directory. ## License -Copyright (C) 2015-2020 |Meso|Star> (<contact@meso-star.com>). Star-Sampling is +Copyright (C) 2015-2021 |Meso|Star> (<contact@meso-star.com>). Star-Sampling is free software released under the CeCILLv2.1 license. You are welcome to redistribute it under certain conditions; refer to the COPYING files for details. diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +# Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) # # This software is a computer program whose purpose is to generate files # used to build the Star-SP library. @@ -74,7 +74,7 @@ rcmake_append_runtime_dirs(_runtime_dirs RSys ${Boost_LIBRARY_DIRS}) # Configure and define targets ################################################################################ set(VERSION_MAJOR 0) -set(VERSION_MINOR 9) +set(VERSION_MINOR 10) set(VERSION_PATCH 0) set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) diff --git a/src/ssp.h b/src/ssp.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a library whose purpose is to generate [pseudo] random * numbers and random variates. @@ -305,8 +305,8 @@ ssp_rng_proxy_get_type /******************************************************************************* * Miscellaneous distributions ******************************************************************************/ -/* Random variate from the exponential distribution with mean `mu': - * P(x) dx = 1/mu * exp(-x / mu) dx */ +/* Random variate from the exponential distribution with mean `1/mu': + * P(x) dx = mu * exp(-x * mu) dx */ SSP_API double ssp_ran_exp (struct ssp_rng* rng, @@ -327,6 +327,31 @@ ssp_ran_exp_float_pdf (const float x, const float mu); +/* Truncated exponential distribution */ +SSP_API double +ssp_ran_exp_truncated + (struct ssp_rng* rng, + const double mu, + const double max); + +SSP_API float +ssp_ran_exp_truncated_float + (struct ssp_rng* rng, + const float mu, + const float max); + +SSP_API double +ssp_ran_exp_truncated_pdf + (const double x, + const double mu, + const double max); + +SSP_API float +ssp_ran_exp_truncated_float_pdf + (const float x, + const float mu, + const float max); + /* Stateless random variate from the gaussian (or normal) distribution * with mean `mu': * P(x) dx = 1 / (sigma*sqrt(2*PI)) * exp(-1/2*((x-mu)/sigma)^2) dx */ diff --git a/src/ssp_ran.c b/src/ssp_ran.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a library whose purpose is to generate [pseudo] random * numbers and random variates. @@ -49,7 +49,7 @@ cosf2sinf(const float d) double ssp_ran_exp(struct ssp_rng* rng, const double mu) { - ASSERT(rng && mu >= 0); + ASSERT(rng && mu > 0); rng_cxx rng_cxx(*rng); RAN_NAMESPACE::exponential_distribution<double> distribution(mu); return distribution(rng_cxx); @@ -58,7 +58,7 @@ ssp_ran_exp(struct ssp_rng* rng, const double mu) float ssp_ran_exp_float(struct ssp_rng* rng, const float mu) { - ASSERT(rng && mu >= 0); + ASSERT(rng && mu > 0); rng_cxx rng_cxx(*rng); RAN_NAMESPACE::exponential_distribution<float> distribution(mu); return distribution(rng_cxx); @@ -67,18 +67,62 @@ ssp_ran_exp_float(struct ssp_rng* rng, const float mu) double ssp_ran_exp_pdf(const double x, const double mu) { - ASSERT(x >= 0 && mu >= 0); + ASSERT(x >= 0 && mu > 0); return mu * exp(-x * mu); } float ssp_ran_exp_float_pdf(const float x, const float mu) { - ASSERT(x >= 0 && mu >= 0); + ASSERT(x >= 0 && mu > 0); return mu * expf(-x * mu); } double +ssp_ran_exp_truncated(struct ssp_rng* rng, const double mu, const double max) +{ + double u, r; + ASSERT(rng && mu > 0 && max > 0); + u = ssp_rng_canonical(rng); + r = -log(1 - u * (1 - exp(-mu * max))) / mu; + return r; +} + +float +ssp_ran_exp_truncated_float(struct ssp_rng* rng, const float mu, const float max) +{ + float u, r; + ASSERT(rng && mu > 0 && max > 0); + u = ssp_rng_canonical_float(rng); + r = -logf(1 - u * (1 - expf(-mu * max))) / mu; + return r; +} + +double +ssp_ran_exp_truncated_pdf(const double x, const double mu, const double max) +{ + ASSERT(x >= 0 && mu > 0 && max > 0); + if(x > max) + return 0; + else { + double norm = mu / (1 - exp(-max * mu)); + return norm * exp(-x * mu); + } +} + +float +ssp_ran_exp_truncated_float_pdf(const float x, const float mu, const float max) +{ + ASSERT(x >= 0 && mu > 0 && max > 0); + if(x > max) + return 0; + else { + float norm = mu / (1 - expf(-max * mu)); + return norm * expf(-x * mu); + } +} + +double ssp_ran_gaussian (struct ssp_rng* rng, const double mu, @@ -200,7 +244,7 @@ ssp_ran_sphere_uniform_float sample[0] = cosf(phi) * sin_theta; sample[1] = sinf(phi) * sin_theta; sample[2] = cos_theta; - if (pdf) *pdf = 1 / (4*(float)PI); + if(pdf) *pdf = 1 / (4*(float)PI); return sample; } @@ -258,7 +302,7 @@ ssp_ran_triangle_uniform sample[0] = v2[0] + one_minus_u * vec0[0] + v * sqrt_u * vec1[0]; sample[1] = v2[1] + one_minus_u * vec0[1] + v * sqrt_u * vec1[1]; sample[2] = v2[2] + one_minus_u * vec0[2] + v * sqrt_u * vec1[2]; - if (pdf) *pdf = 2 / d3_len(d3_cross(tmp, vec0, vec1)); + if(pdf) *pdf = 2 / d3_len(d3_cross(tmp, vec0, vec1)); return sample; } @@ -286,7 +330,7 @@ ssp_ran_triangle_uniform_float sample[0] = v2[0] + one_minus_u * vec0[0] + v * sqrt_u * vec1[0]; sample[1] = v2[1] + one_minus_u * vec0[1] + v * sqrt_u * vec1[1]; sample[2] = v2[2] + one_minus_u * vec0[2] + v * sqrt_u * vec1[2]; - if (pdf) *pdf = 2 / f3_len(f3_cross(tmp, vec0, vec1)); + if(pdf) *pdf = 2 / f3_len(f3_cross(tmp, vec0, vec1)); return sample; } @@ -308,16 +352,16 @@ ssp_ran_tetrahedron_uniform t = ssp_rng_canonical(rng); u = ssp_rng_canonical(rng); - if (s + t > 1) { /* Cut and fold the cube into a prism */ + if(s + t > 1) { /* Cut and fold the cube into a prism */ s = 1 - s; t = 1 - t; } - if (t + u > 1) { /* Cut and fold the prism into a tetrahedron */ + if(t + u > 1) { /* Cut and fold the prism into a tetrahedron */ double swp = u; u = 1 - s - t; t = 1 - swp; } - else if (s + t + u > 1) { + else if(s + t + u > 1) { double swp = u; u = s + t + u - 1; s = 1 - t - swp; @@ -328,7 +372,7 @@ ssp_ran_tetrahedron_uniform d3_add(tmp4, d3_muld(tmp0, v0, a), d3_muld(tmp1, v1, s)), d3_add(tmp5, d3_muld(tmp2, v2, t), d3_muld(tmp3, v3, u))); - if (pdf) + if(pdf) *pdf = ssp_ran_tetrahedron_uniform_pdf(v0, v1, v2, v3); return sample; @@ -352,16 +396,16 @@ ssp_ran_tetrahedron_uniform_float t = ssp_rng_canonical_float(rng); u = ssp_rng_canonical_float(rng); - if (s + t > 1) { /* Cut and fold the cube into a prism */ + if(s + t > 1) { /* Cut and fold the cube into a prism */ s = 1 - s; t = 1 - t; } - if (t + u > 1) { /* Cut and fold the prism into a tetrahedron */ + if(t + u > 1) { /* Cut and fold the prism into a tetrahedron */ float swp = u; u = 1 - s - t; t = 1 - swp; } - else if (s + t + u > 1) { + else if(s + t + u > 1) { float swp = u; u = s + t + u - 1; s = 1 - t - swp; @@ -372,7 +416,7 @@ ssp_ran_tetrahedron_uniform_float f3_add(tmp4, f3_mulf(tmp0, v0, a), f3_mulf(tmp1, v1, s)), f3_add(tmp5, f3_mulf(tmp2, v2, t), f3_mulf(tmp3, v3, u))); - if (pdf) + if(pdf) *pdf = ssp_ran_tetrahedron_uniform_float_pdf(v0, v1, v2, v3); return sample; @@ -392,7 +436,7 @@ ssp_ran_hemisphere_uniform_local sample[0] = cos(phi) * sin_theta; sample[1] = sin(phi) * sin_theta; sample[2] = cos_theta; - if (pdf) *pdf = 1 / (2*PI); + if(pdf) *pdf = 1 / (2*PI); return sample; } @@ -410,7 +454,7 @@ ssp_ran_hemisphere_uniform_float_local sample[0] = cosf(phi) * sin_theta; sample[1] = sinf(phi) * sin_theta; sample[2] = cos_theta; - if (pdf) *pdf = 1 / (2*(float)PI); + if(pdf) *pdf = 1 / (2*(float)PI); return sample; } @@ -429,7 +473,7 @@ ssp_ran_hemisphere_cos_local sample[0] = cos(phi) * sin_theta; sample[1] = sin(phi) * sin_theta; sample[2] = cos_theta; - if (pdf) *pdf = cos_theta / PI; + if(pdf) *pdf = cos_theta / PI; return sample; } @@ -448,7 +492,7 @@ ssp_ran_hemisphere_cos_float_local sample[0] = cosf(phi) * sin_theta; sample[1] = sinf(phi) * sin_theta; sample[2] = cos_theta; - if (pdf) *pdf = cos_theta / (float)PI; + if(pdf) *pdf = cos_theta / (float)PI; return sample; } @@ -600,7 +644,7 @@ ssp_ran_uniform_disk_local pt[0] = r * cos(theta); pt[1] = r * sin(theta); pt[2] = 0; - if (pdf) *pdf = 1 / (radius * radius); + if(pdf) *pdf = 1 / (radius * radius); return pt; } @@ -618,7 +662,7 @@ ssp_ran_uniform_disk_float_local pt[0] = r * cosf(theta); pt[1] = r * sinf(theta); pt[2] = 0; - if (pdf) *pdf = 1 / (radius * radius); + if(pdf) *pdf = 1 / (radius * radius); return pt; } diff --git a/src/ssp_ranst_discrete.c b/src/ssp_ranst_discrete.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a library whose purpose is to generate [pseudo] random * numbers and random variates. diff --git a/src/ssp_ranst_gaussian.c b/src/ssp_ranst_gaussian.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a library whose purpose is to generate [pseudo] random * numbers and random variates. diff --git a/src/ssp_ranst_piecewise_linear.c b/src/ssp_ranst_piecewise_linear.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a library whose purpose is to generate [pseudo] random * numbers and random variates. diff --git a/src/ssp_rng.c b/src/ssp_rng.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a library whose purpose is to generate [pseudo] random * numbers and random variates. @@ -105,31 +105,49 @@ rng_kiss_get(void* data) static res_T rng_kiss_read(void* data, FILE* file) { + uint32_t val[4]; struct rng_kiss* rng = (struct rng_kiss*)data; - int n; + size_t n; ASSERT(data && file); - n = fscanf(file, "%u %u %u %u\n", &rng->x, &rng->y, &rng->z, &rng->c); - return (n == EOF || n < 4) ? RES_IO_ERR : RES_OK; + n = fread(val, sizeof(*val), sizeof(val)/sizeof(*val), file); + if(n != 4) return RES_IO_ERR; + rng->x = val[0]; + rng->y = val[1]; + rng->z = val[2]; + rng->c = val[3]; + return RES_OK; } static res_T rng_kiss_read_cstr(void* data, const char* cstr) { struct rng_kiss* rng = (struct rng_kiss*)data; - int n; + uint32_t val[4]; + size_t sz; ASSERT(data && cstr); - n = sscanf(cstr, "%u %u %u %u\n", &rng->x, &rng->y, &rng->z, &rng->c); - return (n == EOF || n < 4) ? RES_IO_ERR : RES_OK; + sz = strlen(cstr); + if(sz < sizeof(val)) return RES_IO_ERR; + memcpy(val, cstr, sizeof(val)); + rng->x = val[0]; + rng->y = val[1]; + rng->z = val[2]; + rng->c = val[3]; + return RES_OK; } static res_T rng_kiss_write(const void* data, FILE* file) { const struct rng_kiss* rng = (const struct rng_kiss*)data; - int res; + uint32_t val[4]; + size_t n; ASSERT(data && file); - res = fprintf(file, "%u %u %u %u\n", rng->x, rng->y, rng->z, rng->c); - return res < 0 ? RES_IO_ERR : RES_OK; + val[0] = rng->x; + val[1] = rng->y; + val[2] = rng->z; + val[3] = rng->c; + n = fwrite(val, sizeof(*val), sizeof(val)/sizeof(*val), file); + return (n != 4 ? RES_IO_ERR : RES_OK); } static res_T @@ -140,15 +158,18 @@ rng_kiss_write_cstr size_t* out_len) { const struct rng_kiss* rng = (const struct rng_kiss*)data; - int len = 0; + uint32_t val[4]; ASSERT(data); - len = snprintf(buf, bufsz, "%u %u %u %u\n", rng->x, rng->y, rng->z, rng->c); - CHK(len > 0); - if((size_t)len >= (bufsz - 1/*null char*/)) { - buf[bufsz-1] = '\0'; + val[0] = rng->x; + val[1] = rng->y; + val[2] = rng->z; + val[3] = rng->c; + if(bufsz >= sizeof(val) + 1/*null char*/) { + memcpy(buf, val, sizeof(val)); + buf[sizeof(val)] = '\0'; } - if(out_len) *out_len = (size_t)len; + if(out_len) *out_len = sizeof(val); return RES_OK; } @@ -451,7 +472,7 @@ rng_cxx_init<aes_T>(struct mem_allocator* allocator, void* data) { (void) allocator; - if (!haveAESNI()) { + if(!haveAESNI()) { /* AES-NI instructions not available on this hardware */ return RES_BAD_OP; } @@ -523,7 +544,7 @@ rng_release(ref_T* ref) ASSERT(ref); rng = CONTAINER_OF(ref, struct ssp_rng, ref); if(rng->state) { - if (rng->type.release) { + if(rng->type.release) { rng->type.release(rng->state); } MEM_RM(rng->allocator, rng->state); @@ -742,7 +763,7 @@ ssp_rng_write(const struct ssp_rng* rng, FILE* stream) res_T ssp_rng_write_cstr (const struct ssp_rng* rng, - char* buf, + char* buf, const size_t bufsz, size_t* len) { @@ -753,13 +774,13 @@ ssp_rng_write_cstr double ssp_rng_entropy(const struct ssp_rng* rng) { - if (!rng) FATAL("The Random Number Generator is NULL\n"); + if(!rng) FATAL("The Random Number Generator is NULL\n"); return rng->type.entropy(rng->state); } res_T ssp_rng_discard(struct ssp_rng* rng, uint64_t n) { - if (!rng) FATAL("The Random Number Generator is NULL\n"); + if(!rng) FATAL("The Random Number Generator is NULL\n"); return rng->type.discard(rng->state, n); } diff --git a/src/ssp_rng_c.h b/src/ssp_rng_c.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a library whose purpose is to generate [pseudo] random * numbers and random variates. diff --git a/src/ssp_rng_proxy.c b/src/ssp_rng_proxy.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a library whose purpose is to generate [pseudo] random * numbers and random variates. diff --git a/src/test_ssp_ran_circle.c b/src/test_ssp_ran_circle.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, diff --git a/src/test_ssp_ran_circle.h b/src/test_ssp_ran_circle.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, diff --git a/src/test_ssp_ran_discrete.c b/src/test_ssp_ran_discrete.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a library whose purpose is to generate [pseudo] random * numbers and random variates. diff --git a/src/test_ssp_ran_discrete.h b/src/test_ssp_ran_discrete.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a program whose purpose is to test the spp library. * diff --git a/src/test_ssp_ran_gaussian.c b/src/test_ssp_ran_gaussian.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a program whose purpose is to test the spp library. * diff --git a/src/test_ssp_ran_gaussian.h b/src/test_ssp_ran_gaussian.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a library whose purpose is to generate [pseudo] random * numbers and random variates. diff --git a/src/test_ssp_ran_hemisphere.c b/src/test_ssp_ran_hemisphere.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, diff --git a/src/test_ssp_ran_hemisphere.h b/src/test_ssp_ran_hemisphere.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, diff --git a/src/test_ssp_ran_hg.c b/src/test_ssp_ran_hg.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, diff --git a/src/test_ssp_ran_hg.h b/src/test_ssp_ran_hg.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, diff --git a/src/test_ssp_ran_piecewise_linear.c b/src/test_ssp_ran_piecewise_linear.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a program whose purpose is to test the spp library. * diff --git a/src/test_ssp_ran_piecewise_linear.h b/src/test_ssp_ran_piecewise_linear.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a program whose purpose is to test the spp library. * diff --git a/src/test_ssp_ran_sphere.c b/src/test_ssp_ran_sphere.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, diff --git a/src/test_ssp_ran_sphere.h b/src/test_ssp_ran_sphere.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, diff --git a/src/test_ssp_ran_sphere_cap.c b/src/test_ssp_ran_sphere_cap.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, diff --git a/src/test_ssp_ran_sphere_cap.h b/src/test_ssp_ran_sphere_cap.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, diff --git a/src/test_ssp_ran_tetrahedron.c b/src/test_ssp_ran_tetrahedron.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, diff --git a/src/test_ssp_ran_tetrahedron.h b/src/test_ssp_ran_tetrahedron.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, diff --git a/src/test_ssp_ran_triangle.c b/src/test_ssp_ran_triangle.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, diff --git a/src/test_ssp_ran_triangle.h b/src/test_ssp_ran_triangle.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, diff --git a/src/test_ssp_ran_uniform_disk.c b/src/test_ssp_ran_uniform_disk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a program whose purpose is to test the spp library. * diff --git a/src/test_ssp_ran_uniform_disk.h b/src/test_ssp_ran_uniform_disk.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a program whose purpose is to test the spp library. * diff --git a/src/test_ssp_rng.c b/src/test_ssp_rng.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a program whose purpose is to test the spp library. * @@ -51,7 +51,7 @@ test_rng(const struct ssp_rng_type* type) uint64_t datai1[NRAND]; double datad[NRAND]; float dataf[NRAND]; - size_t len; + size_t len = 0; char buf[512]; char* cstr = NULL; int i, j; @@ -100,7 +100,7 @@ test_rng(const struct ssp_rng_type* type) CHK(ssp_rng_create(NULL, type, &rng1) == RES_OK); CHK(ssp_rng_create(NULL, type, &rng2) == RES_OK); CHK(ssp_rng_discard(rng1, 10) == (can_discard ? RES_OK : RES_BAD_OP)); - if (type != &ssp_rng_random_device) { + if(type != &ssp_rng_random_device) { for (i = 0; i < 10; i++) ssp_rng_get(rng2); CHK(ssp_rng_get(rng1) == ssp_rng_get(rng2)); } @@ -198,6 +198,7 @@ test_rng(const struct ssp_rng_type* type) CHK(ssp_rng_write_cstr(rng, NULL, 0, NULL) == (can_rw ? RES_OK : RES_BAD_OP)); CHK(ssp_rng_write_cstr(rng, NULL, 0, &len) == (can_rw ? RES_OK : RES_BAD_OP)); cstr = mem_calloc(len+1, 1); + CHK(cstr != NULL); CHK(ssp_rng_write_cstr(rng, cstr, len+1, NULL) == (can_rw ? RES_OK : RES_BAD_OP)); /* Reserialize the RNG state */ @@ -206,6 +207,8 @@ test_rng(const struct ssp_rng_type* type) FOR_EACH(i, 0, NRAND) datai0[i] = ssp_rng_get(rng); + fflush(stream); + CHK(ssp_rng_read(NULL, NULL) == RES_BAD_ARG); CHK(ssp_rng_read(rng, NULL) == RES_BAD_ARG); CHK(ssp_rng_read(NULL, stream) == RES_BAD_ARG); diff --git a/src/test_ssp_rng.h b/src/test_ssp_rng.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a program whose purpose is to test the spp library. * diff --git a/src/test_ssp_rng_proxy.c b/src/test_ssp_rng_proxy.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a program whose purpose is to test the spp library. * diff --git a/src/test_ssp_rng_proxy.h b/src/test_ssp_rng_proxy.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is a program whose purpose is to test the spp library. * diff --git a/src/test_ssp_utils.h b/src/test_ssp_utils.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015-2020 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2015-2021 |Meso|Star> (contact@meso-star.com) * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use,