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_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.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)