mlx_rs::random

Function uniform_device

Source
pub fn uniform_device<'a, E: Into<Array>, T: ArrayElement>(
    lower: E,
    upper: E,
    shape: impl IntoOption<&'a [i32]>,
    key: impl Into<Option<&'a Array>>,
    stream: impl AsRef<Stream>,
) -> Result<Array>
Expand description

Generate uniformly distributed random numbers. The values are sampled uniformly in the half-open interval [lower, upper). The lower and upper bound can be scalars or arrays and must be broadcastable to shape.

ยงParams

  • lower: Lower bound of the distribution.
  • upper: Upper bound of the distribution.
  • shape (optional): Shape of the output. Default is &[].
  • key (optional): A PRNG key.
let key = mlx_rs::random::key(0).unwrap();

// create an array of shape `[50]` type f32 values in the range [0, 10)
let array = mlx_rs::random::uniform::<_, f32>(0, 10, &[50], &key);

// same, but in range [0.5, 1)
let array = mlx_rs::random::uniform::<_, f32>(0.5f32, 1f32, &[50], &key);