kaolin.ops.random¶
API¶
-
kaolin.ops.random.
get_state
()¶ Returns the generator states for generating random numbers.
Mostly used in pair with
set_state()
pytest –doctest-modules kaolin/ - https://pytorch.org/docs/stable/generated/torch.get_rng_state.html#torch.get_rng_state - https://docs.python.org/3/library/random.html#random.getstate - https://numpy.org/doc/stable/reference/random/generated/numpy.random.set_state.html#numpy.random.set_stateReturns: the states for the corresponding modules (torch, random, numpy). Return type: (torch.ByteTensor, tuple, tuple) Example
>>> torch_state, random_state, numpy_state = get_state() >>> s = torch.randn((1, 3)) >>> set_state(torch_state, random_state, numpy_state)
-
kaolin.ops.random.
manual_seed
(torch_seed, random_seed=None, numpy_seed=None)¶ Set the seed for random and torch modules.
Parameters:
-
kaolin.ops.random.
random_shape_per_tensor
(batch_size, min_shape=None, max_shape=None)¶ Generate random
shape_per_tensor
.Parameters: Returns: A shape_per_tensor (2D).
Return type: (torch.LongTensor)
Example
>>> _ = torch.random.manual_seed(1) >>> random_shape_per_tensor(3, min_shape=(4, 4), max_shape=(10, 10)) tensor([[ 4, 7], [ 7, 7], [ 8, 10]])
-
kaolin.ops.random.
random_tensor
(low, high, shape, dtype=torch.float32, device='cpu')¶ Generate a random tensor.
Parameters: - low (float) – the lowest value to be drawn from the distribution.
- high (float) – the highest value to be drawn from the distribution.
- shape (list, tuple or torch.LongTensor) – the desired output shape.
- dtype (torch.dtype) – the desired output dtype.
- device (torch.device) – the desired output device.
Returns: a random generated tensor.
Return type: Example
>>> _ = torch.random.manual_seed(1) >>> random_tensor(4., 5., (3, 3), dtype=torch.float, device='cpu') tensor([[4.7576, 4.2793, 4.4031], [4.7347, 4.0293, 4.7999], [4.3971, 4.7544, 4.5695]])
-
kaolin.ops.random.
set_state
(torch_state, random_state, numpy_state)¶ Set the generator states for generating random numbers.
Mostly used in pair with
get_state()
Parameters: Example
>>> torch_state, random_state, numpy_state = get_state() >>> s = torch.randn((1, 3)) >>> set_state(torch_state, random_state, numpy_state)