ocnn.utils

trunc_div

Wraps torch.div() for compatibility.

meshgrid

Wraps torch.meshgrid() for compatibility.

cumsum

Extends torch.cumsum() with the input argument exclusive.

scatter_add

Reduces all values from the src tensor into out at the indices specified in the index tensor along a given axis dim.

xavier_uniform_

Initialize convolution weights with the same method as torch.nn.init.xavier_uniform_.

resize_with_last_val

Resizes the number of elements of list_in to num with the last element of list_in if its number of elements is smaller than num.

list2str

Returns a string representation of list_in.

build_example_octree

Builds an example octree on CPU from at most 3 points.

trunc_div(input, other)[source]

Wraps torch.div() for compatibility. It rounds the results of the division towards zero and is equivalent to C-style integer division.

meshgrid(*tensors, indexing: str | None = None)[source]

Wraps torch.meshgrid() for compatibility.

cumsum(data: Tensor, dim: int, exclusive: bool = False)[source]

Extends torch.cumsum() with the input argument exclusive.

Parameters:
  • data (torch.Tensor) – The input data.

  • dim (int) – The dimension to do the operation over.

  • exclusive (bool) – If false, the behavior is the same as torch.cumsum(); if true, returns the cumulative sum exclusively. Note that if ture, the shape of output tensor is larger by 1 than data in the dimension where the computation occurs.

scatter_add(src: Tensor, index: Tensor, dim: int = -1, out: Tensor | None = None, dim_size: int | None = None) Tensor[source]

Reduces all values from the src tensor into out at the indices specified in the index tensor along a given axis dim. This is just a wrapper of torch.scatter() in a boardcasting fashion.

Parameters:
  • src (torch.Tensor) – The source tensor.

  • index (torch.Tensor) – The indices of elements to scatter.

  • dim (int) – The axis along which to index, (default: -1).

  • out (torch.Tensor or None) – The destination tensor.

  • dim_size (int or None) – If out is not given, automatically create output with size dim_size at dimension dim. If dim_size is not given, a minimal sized output tensor according to index.max() + 1 is returned.

xavier_uniform_(weights: Tensor)[source]

Initialize convolution weights with the same method as torch.nn.init.xavier_uniform_.

torch.nn.init.xavier_uniform_ initialize a tensor with shape (out_c, in_c, kdim), which can not be used in ocnn.nn.OctreeConv since the the shape of OctreeConv.weights is (kdim, in_c, out_c).

resize_with_last_val(list_in: list, num: int = 3)[source]

Resizes the number of elements of list_in to num with the last element of list_in if its number of elements is smaller than num.

list2str(list_in: list)[source]

Returns a string representation of list_in.

build_example_octree(depth: int = 5, full_depth: int = 2, pt_num: int = 3)[source]

Builds an example octree on CPU from at most 3 points.