kaolin.ops.random

API

kaolin.ops.random.get_state()

Returns the generator states for generating random numbers.

Mostly used in pair with set_state().

See also:

Returns

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
  • torch_seed (int) – The desired seed for torch module.

  • random_seed (int) – The desired seed for random module. Default: torch_seed value.

  • numpy_seed (int) – The desired seed for numpy module. Default: torch_seed value.

kaolin.ops.random.random_shape_per_tensor(batch_size, min_shape=None, max_shape=None)

Generate random shape_per_tensor.

Parameters
  • batch_size (int) – Batch size (first dimension) of the generated tensor.

  • min_shape (list, tuple or torch.LongTensor) – Minimum values for each dimension of generated shapes. Default: 1 for each dimensions.

  • max_shape (list, tuple or torch.LongTensor) – maximum values for each dimension of generated shapes.

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
  • batch_size (int) – The desired number of octrees.

  • max_level (int) – The desired max level of the octrees.

  • device (torch.device) – The desired output device. Default: ‘cpu’.

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. Default: torch.float.

  • device (torch.device) – the desired output device. Default: ‘cpu’

Returns

a random generated tensor.

Return type

(torch.Tensor)

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.sample_spherical_coords(shape, azimuth_low=0.0, azimuth_high=6.283185307179586, elevation_low=0.0, elevation_high=1.5707963267948966, device='cpu', dtype=torch.float32)

Sample spherical coordinates with a uniform distribution.

Parameters
  • shape (Sequence) – shape of outputs.

  • azimuth_low (float, optional) – lower bound for azimuth, in radian. Default: 0.

  • azimuth_high (float, optional) – higher bound for azimuth, in radian. Default: 2 * pi.

  • elevation_low (float, optional) – lower bound for elevation, in radian. Default: 0.

  • elevation_high (float, optional) – higher bound for elevation, in radian. Default: pi / 2.

  • device (torch.device, optional) – device of the output tensor. Default: ‘cpu’.

  • dtype (torch.dtype, optional) – dtype of the output tensor. Default: torch.float.

Returns

the azimuth and elevation, both of desired shape.

Return type

(torch.Tensor, torch.Tensor)

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
  • torch_state (torch.ByteTensor) – the state of torch module.

  • random_state (tuple) – the state of random module.

  • numpy_state (tuple) – the state of numpy module.

Example

>>> torch_state, random_state, numpy_state = get_state()
>>> s = torch.randn((1, 3))
>>> set_state(torch_state, random_state, numpy_state)