Skip to contents

Samples from a normal distribution with mean \(\mu\) and standard deviation \(\sigma\) using the Box-Muller transform.

Usage

nv_rnorm(shape, initial_state, dtype = "f32", mu = 0, sigma = 1)

Arguments

shape

(integer())
Shape.

initial_state

(tensorish)
RNG state (ui64[2]).

dtype

(character(1) | stablehlo::TensorDataType)
Data type.

mu

(tensorish)
Mean.

sigma

(tensorish)
Standard deviation. Must be positive, otherwise results are invalid.

Value

(list() of tensorish)
List of two elements: the updated RNG state and the sampled values.

Covariance

To implement a covariance structure use Cholesky decomposition.

Examples

jit_eval({
  state <- nv_rng_state(42L)
  result <- nv_rnorm(c(2, 3), state)
  result[[2]]
})
#> AnvilTensor
#>  -0.0675  0.9489  1.9457
#>  -0.5255  1.2002  0.0008
#> [ CPUf32{2,3} ]