From ffc77ee1d571d661f91f7b5b9b8f6b16831b2bc8 Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Sun, 15 Mar 2020 18:05:39 +0900 Subject: [PATCH] Implement optimization for sobol sampler. This significantly increases the sobol sampler's speed, especially for higher sample counts. --- sub_crates/sobol/src/lib.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/sub_crates/sobol/src/lib.rs b/sub_crates/sobol/src/lib.rs index 07e93bd..f55543d 100644 --- a/sub_crates/sobol/src/lib.rs +++ b/sub_crates/sobol/src/lib.rs @@ -98,14 +98,12 @@ fn sobol_u32(dimension: u32, mut index: u32) -> u32 { assert!((dimension as usize) < NUM_DIMENSIONS); let mut result = 0; - let mut i = (dimension as usize) * SIZE; + let mut i = dimension * SIZE as u32; while index != 0 { - if (index & 1) != 0 { - result ^= MATRICES[i]; - } - - index >>= 1; - i += 1; + let j = index.trailing_zeros(); + result ^= MATRICES[(i + j) as usize]; + i += j + 1; + index >>= j + 1; } result