Shortcuts

nerfacc.inclusive_sum

nerfacc.inclusive_sum(inputs, packed_info=None, indices=None)

Inclusive Sum that supports flattened tensor.

This function is equivalent to torch.cumsum(inputs, dim=-1), but allows for a flattened input tensor and a packed_info tensor that specifies the chunks in the flattened input.

Parameters:
  • inputs (Tensor) – The tensor to be summed. Can be either a N-D tensor, or a flattened tensor with either packed_info or indices specified.

  • packed_info (Optional[Tensor]) – A tensor of shape (n_rays, 2) that specifies the start and count of each chunk in the flattened input tensor, with in total n_rays chunks. If None, the input is assumed to be a N-D tensor and the sum is computed along the last dimension. Default is None.

  • indices (Optional[Tensor]) – A flattened tensor with the same shape as inputs.

Returns:

The inclusive sum with the same shape as the input tensor.

Return type:

Tensor

Example:

>>> inputs = torch.tensor([1., 2., 3., 4., 5., 6., 7., 8., 9.], device="cuda")
>>> packed_info = torch.tensor([[0, 2], [2, 3], [5, 4]], device="cuda")
>>> inclusive_sum(inputs, packed_info)
tensor([ 1.,  3.,  3.,  7., 12.,  6., 13., 21., 30.], device='cuda:0')