torch.func._random.uniform_#
- torch.func._random.uniform_(key, result, *, low=0.0, high=1.0)[source]#
Fill
resultin-place with uniform random values from a PRNG key.The values are drawn uniformly from the interval
[low, high). The output is fully determined by the key, so calling with the same key always produces the same result.Supports batched keys: if
keyhas shape(*batch, K), the leading dimensions ofresultmust be broadcastable with*batchand each key independently generates its slice of the output.Gradients flow to tensor
low/highas for a reparameterized sample (liketorch.distributions.Distribution.rsample()).- Parameters:
key (Tensor) – A PRNG key returned by
key(),split(), orfold_in().result (Tensor) – The output tensor to fill in-place.
low (float or Tensor) – Lower bound (inclusive) of the uniform distribution. A floating-point tensor must broadcast to
resultand gives a bound per element. Default:0.0.high (float or Tensor) – Upper bound (exclusive) of the uniform distribution. A floating-point tensor must broadcast to
resultand gives a bound per element. Default:1.0.
- Returns:
result, filled with uniform random values.- Return type:
Example:
>>> key = torch.func._random.key(42, device="cuda") >>> result = torch.empty(1000, device="cuda") >>> torch.func._random.uniform_(key, result)