From: Szabolcs Horvat Date: Sun, 20 Nov 2022 13:28:36 +0000 (+0000) Subject: upstream: fixed: benchmarks: RNG call: explicit order X-Git-Tag: archive/raspbian/0.10.2+ds-2+rpi1^2~4 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=6c60ea84f13158644888a1c018260783a39a4350;p=igraph.git upstream: fixed: benchmarks: RNG call: explicit order Origin: upstream Forwarded: not-needed Last-Update: 2022-11-20 Upstream patch 3ae6dcb: refactor RNG calls [in t/b/igraph_distances.c] to guarantee evaluation order Gbp-Pq: Name upstream-fixed-benchmarks-ig_distances-RNG-explicit_order.patch --- diff --git a/tests/benchmarks/igraph_distances.c b/tests/benchmarks/igraph_distances.c index 1a0fb46..51ba2d2 100644 --- a/tests/benchmarks/igraph_distances.c +++ b/tests/benchmarks/igraph_distances.c @@ -46,7 +46,10 @@ int main(void) { RNG_BEGIN(); for (igraph_integer_t i=0; i < trunc(0.005 * igraph_ecount(&g)); i++) { - VECTOR(weights)[RNG_INTEGER(0, igraph_ecount(&g)-1)] = RNG_UNIF(-0.05, 0); + /* For reproducibility, do not write two RNG_...() calls on the same line + * as the C language does not guarantee any evaluation order between them. */ + igraph_real_t w = RNG_UNIF(-0.05, 0); + VECTOR(weights)[RNG_INTEGER(0, igraph_ecount(&g)-1)] = w; } RNG_END(); @@ -97,7 +100,10 @@ int main(void) { RNG_BEGIN(); for (igraph_integer_t i=0; i < trunc(0.002 * igraph_ecount(&g)); i++) { - VECTOR(weights)[RNG_INTEGER(0, igraph_ecount(&g)-1)] = RNG_UNIF(-0.02, 0); + /* For reproducibility, do not write two RNG_...() calls on the same line + * as the C language does not guarantee any evaluation order between them. */ + igraph_real_t w = RNG_UNIF(-0.02, 0); + VECTOR(weights)[RNG_INTEGER(0, igraph_ecount(&g)-1)] = w; } RNG_END(); @@ -148,7 +154,10 @@ int main(void) { RNG_BEGIN(); for (igraph_integer_t i=0; i < trunc(0.01 * igraph_ecount(&g)); i++) { - VECTOR(weights)[RNG_INTEGER(0, igraph_ecount(&g)-1)] = RNG_UNIF(-0.02, 0); + /* For reproducibility, do not write two RNG_...() calls on the same line + * as the C language does not guarantee any evaluation order between them. */ + igraph_real_t w = RNG_UNIF(-0.02, 0); + VECTOR(weights)[RNG_INTEGER(0, igraph_ecount(&g)-1)] = w; } RNG_END();