upstream: fixed: benchmarks: RNG call: explicit order
authorSzabolcs Horvat <szhorvat@gmail.com>
Sun, 20 Nov 2022 13:28:36 +0000 (13:28 +0000)
committerJerome Benoit <calculus@rezozer.net>
Sun, 20 Nov 2022 13:28:36 +0000 (13:28 +0000)
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

tests/benchmarks/igraph_distances.c

index 1a0fb467f9c2bab150241cc50f479642112468ec..51ba2d2459575f98e5c52561438abd96d52ff11a 100644 (file)
@@ -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();