pub fn with_default_generator<R, F>(
space: LogicalMemorySpace,
f: F,
) -> Result<R>Expand description
Run a closure with a shared default generator for the requested memory space.
The default generator is process-global and advances across calls. CPU memory spaces share a CPU default generator, while each CUDA device gets its own device-bound default generator.
ยงExamples
use tenferro_device::{with_default_generator, LogicalMemorySpace};
let value = with_default_generator(LogicalMemorySpace::MainMemory, |generator| {
Ok(generator.sample_uniform_f64())
}).unwrap();
assert!(value >= 0.0 && value < 1.0);