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_state- Returns
the states for the corresponding modules (torch, random, numpy).
- Return type
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.
- 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_spc_octrees(batch_size, max_level, device='cpu')¶
Generate random SPC octrees.
- Parameters
- Returns
A batch of randomly generated octrees.
The length of each octree.
- Return type
(torch.ByteTensor, torch.IntTensor)
Example
>>> _ = torch.random.manual_seed(1) >>> random_spc_octrees(2, 3, device='cpu') (tensor([ 71, 180, 220, 9, 134, 59, 42, 102, 210, 193, 204, 190, 107, 24, 104, 151, 13, 7, 18, 107, 16, 154, 57, 110, 19, 22, 230, 48, 135, 65, 69, 147, 148, 184, 203, 229, 114, 232, 18, 231, 241, 195], dtype=torch.uint8), tensor([19, 23], dtype=torch.int32))
- 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)