Generator

Struct Generator 

Source
pub struct Generator { /* private fields */ }
Expand description

Pseudo-random number generator used across the tenferro workspace.

The CPU half uses an MT19937 engine seeded from a u64. CUDA execution uses the same public Generator surface but advances an internal seed/offset pair that device kernels consume through a Philox-style counter-based scheme.

§Examples

use tenferro_device::Generator;

let mut generator = Generator::cpu(1234);
let sample = generator.sample_uniform_f64();
assert!(sample >= 0.0 && sample < 1.0);

Implementations§

Source§

impl Generator

Source

pub fn cpu(seed: u64) -> Self

Create a CPU generator from a seed.

§Examples
use tenferro_device::Generator;

let _generator = Generator::cpu(42);
Source

pub fn sample_uniform_f64(&mut self) -> f64

Draw a floating-point sample from the half-open interval [0, 1).

§Examples
use tenferro_device::Generator;

let mut generator = Generator::cpu(7);
let x = generator.sample_uniform_f64();
assert!(x >= 0.0 && x < 1.0);
Source

pub fn sample_standard_normal_f64(&mut self) -> f64

Draw a standard normal sample using Box-Muller sampling.

§Examples
use tenferro_device::Generator;

let mut generator = Generator::cpu(7);
let _z = generator.sample_standard_normal_f64();
Source

pub fn sample_integer_i32(&mut self, low: i32, high: i32) -> Result<i32>

Draw an integer sample from the half-open interval [low, high).

§Errors

Returns Error::InvalidArgument if low >= high.

§Examples
use tenferro_device::Generator;

let mut generator = Generator::cpu(7);
let x = generator.sample_integer_i32(-3, 7).unwrap();
assert!((-3..7).contains(&x));

Trait Implementations§

Source§

impl Debug for Generator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.