Skip to main content

ArrayRng

Struct ArrayRng 

Source
pub struct ArrayRng<A> { /* private fields */ }
Expand description

Random number generator for ndarray

Uses ChaCha8Rng internally because StdRng does not implement Clone in rand 0.10.

Implementations§

Source§

impl<A: Float> ArrayRng<A>

Source

pub fn new() -> Self

Creates a new random number generator with the default seed.

Source

pub fn from_seed(seed: u64) -> Self

Creates a new random number generator with the specified seed.

Source

pub fn as_rng(&self) -> &ChaCha8Rng

Returns a reference to the internal RNG

Source

pub fn as_rng_mut(&mut self) -> &mut ChaCha8Rng

Returns a mutable reference to the internal RNG

Source

pub fn random(&mut self, shape: &[usize]) -> NdArray<A>

Creates a uniform random array in the specified shape. Values are in the range [0, 1)

Source

pub fn normal(&mut self, shape: &[usize], mean: f64, std: f64) -> NdArray<A>

Creates a normal random array in the specified shape. Values are drawn from a normal distribution with the specified mean and standard deviation.

Source

pub fn uniform(&mut self, shape: &[usize], low: f64, high: f64) -> NdArray<A>

Creates a uniform random array in the specified shape. Values are in the range [low, high).

Source

pub fn glorot_uniform(&mut self, shape: &[usize]) -> NdArray<A>

Creates a random array with Glorot/Xavier uniform initialization. For a tensor with shape (in_features, out_features), samples are drawn from Uniform(-sqrt(6/(in_features+out_features)), sqrt(6/(in_features+out_features))).

Source

pub fn glorot_normal(&mut self, shape: &[usize]) -> NdArray<A>

Creates a random array with Glorot/Xavier normal initialization. For a tensor with shape (in_features, out_features), samples are drawn from Normal(0, sqrt(2/(in_features+out_features))).

Source

pub fn he_uniform(&mut self, shape: &[usize]) -> NdArray<A>

Creates a random array with He/Kaiming uniform initialization. For a tensor with shape (in_features, out_features), samples are drawn from Uniform(-sqrt(6/in_features), sqrt(6/in_features)).

Source

pub fn he_normal(&mut self, shape: &[usize]) -> NdArray<A>

Creates a random array with He/Kaiming normal initialization. For a tensor with shape (in_features, out_features), samples are drawn from Normal(0, sqrt(2/in_features)).

Source

pub fn standard_normal(&mut self, shape: &[usize]) -> NdArray<A>

Creates a random array from the standard normal distribution.

Source

pub fn standard_uniform(&mut self, shape: &[usize]) -> NdArray<A>

Creates a random array from the standard uniform distribution.

Source

pub fn bernoulli(&mut self, shape: &[usize], p: f64) -> NdArray<A>

Creates a random array from the bernoulli distribution.

Source

pub fn exponential(&mut self, shape: &[usize], lambda: f64) -> NdArray<A>

Creates a random array from the exponential distribution.

Source

pub fn log_normal( &mut self, shape: &[usize], mean: f64, stddev: f64, ) -> NdArray<A>

Creates a random array from the log-normal distribution.

Source

pub fn gamma( &mut self, shape: &[usize], shape_param: f64, scale: f64, ) -> NdArray<A>

Creates a random array from the gamma distribution.

Trait Implementations§

Source§

impl<A: Clone> Clone for ArrayRng<A>

Source§

fn clone(&self) -> ArrayRng<A>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<A: Float> Default for ArrayRng<A>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<A> TryRng for ArrayRng<A>

Source§

type Error = Infallible

The type returned in the event of a RNG error. Read more
Source§

fn try_next_u32(&mut self) -> Result<u32, Self::Error>

Return the next random u32.
Source§

fn try_next_u64(&mut self) -> Result<u64, Self::Error>

Return the next random u64.
Source§

fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Self::Error>

Fill dst entirely with random data.

Auto Trait Implementations§

§

impl<A> Freeze for ArrayRng<A>

§

impl<A> RefUnwindSafe for ArrayRng<A>
where A: RefUnwindSafe,

§

impl<A> Send for ArrayRng<A>
where A: Send,

§

impl<A> Sync for ArrayRng<A>
where A: Sync,

§

impl<A> Unpin for ArrayRng<A>
where A: Unpin,

§

impl<A> UnsafeUnpin for ArrayRng<A>

§

impl<A> UnwindSafe for ArrayRng<A>
where A: UnwindSafe,

Blanket Implementations§

Source§

impl<R> TryRngCore for R
where R: TryRng,

Source§

type Error = <R as TryRng>::Error

👎Deprecated since 0.10.0:

use TryRng instead

Error type.
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R> Rng for R
where R: TryRng<Error = Infallible> + ?Sized,

Source§

fn next_u32(&mut self) -> u32

Return the next random u32.
Source§

fn next_u64(&mut self) -> u64

Return the next random u64.
Source§

fn fill_bytes(&mut self, dst: &mut [u8])

Fill dest with random data. Read more
Source§

impl<R> RngExt for R
where R: Rng + ?Sized,

Source§

fn random<T>(&mut self) -> T

Return a random value via the StandardUniform distribution. Read more
Source§

fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>

Return an iterator over random variates Read more
Source§

fn random_range<T, R>(&mut self, range: R) -> T
where T: SampleUniform, R: SampleRange<T>,

Generate a random value in the given range. Read more
Source§

fn random_bool(&mut self, p: f64) -> bool

Return a bool with a probability p of being true. Read more
Source§

fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool

Return a bool with a probability of numerator/denominator of being true. Read more
Source§

fn sample<T, D>(&mut self, distr: D) -> T
where D: Distribution<T>,

Sample a new value, using the given distribution. Read more
Source§

fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>
where D: Distribution<T>, Self: Sized,

Create an iterator that generates values using the given distribution. Read more
Source§

fn fill<T>(&mut self, dest: &mut [T])
where T: Fill,

Fill any type implementing Fill with random data Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<R> RngCore for R
where R: Rng,