Misc Utilities API

lightplane.misc_utils.assert_shape(x: Tensor, shape: Tuple[int, ...])[source]

Helper function to assert the shape of a tensor.

Parameters:
  • x – Input tensor.

  • shape – Expected shape of the input tensor.

lightplane.misc_utils.check_grid_and_color_grid(grid: List[torch.Tensor] | torch.Tensor, color_grid: List[torch.Tensor] | torch.Tensor | None, grid_sizes: List[List[int]] | None = None, color_grid_sizes: List[List[int]] | None = None)[source]

Helper function to check the shape of grid and grid_sizes, as well as color_grid and color_grid_sizes.

It checks the following:
  1. grid and color_grid should have the same type if color_grid is not None.

  2. grid and color_grid should have the same batch size and feature dimension if grid is a list.

  3. grid_sizes and color_grid_sizes should be compatible with the shapes of grid and color_grid respectively.

lightplane.misc_utils.flatten_grid(grid: Tuple[Tensor, ...]) Tuple[Tensor, Tensor][source]

Flattens a list of grids (grid-list) into a single 2D tensor, and return the grid sizes.

Parameters:

grid – List of grids to flatten.

Returns:
  • grid_flat – Flattened grid, 2D tensor.

  • grid_sizes – Grid sizes, List[List[int]]

lightplane.misc_utils.if_not_none_else(x: Any, y: Any) Any[source]

If x is not None, return x, else return y.

lightplane.misc_utils.is_in_bounds(points: Tensor) BoolTensor[source]

Check if the points are within the bounds of [-1, 1] in all dimensions.

lightplane.misc_utils.pad_feature_to_block_size(feature: Tensor, block_size: int) Tensor[source]

Pads the feature to a multiple of block size, similar to pad_to_block_size in Ray Class.

Parameters:

block_size – Block size to pad to.

lightplane.misc_utils.process_and_flatten_grid(grid: List[torch.Tensor] | torch.Tensor, color_grid: List[torch.Tensor] | torch.Tensor | None, grid_sizes: List[List[int]] | None = None, color_grid_sizes: List[List[int]] | None = None)[source]

Helper function to process and flatten the grid and color_grid.

If grid is a grid-list, it flattens the grid-list into a single 2D tensor, and return the grid sizes in the tensor form.

If grid is a tensor, it converts the `grid_size`s into tensor form.

If color_grid is not None, it processes and flattens the color_grid in the same way as grid.

lightplane.misc_utils.unflatten_grid(grid: Tensor, grid_sizes: Tensor) Tuple[Tensor, ...][source]

Unflattens a 2D tensor into a list of grids (grid-list), given the grid sizes.

Parameters:
  • grid – Flattened grid, 2D tensor.

  • grid_sizes – Grid sizes, e.g. grid_sizes = torch.tensor([[1, 32, 32, 32, 64]])

Returns:

grid_list – List of grids. List[torch.Tensor, …]