code: def integral_tensor(
      input: Tensor, dim: Optional[Tuple[int, ...]] = None
  ) -> Tensor:
      """Calculates integral of the input tensor.
  
      The algorithm computes the integral image by summing over the specified dimensions.
  
      In case dim is specified, the contained dimensions must be unique and sorted in ascending order
      and not exceed the number of dimensions of the input tensor.
  
      Args:
          input: the input tensor with shape :math:`(*, D)`. Where D is the number of dimensions.
          dim: the dimension to be summed.
  
      Returns:
          Integral tensor for the input tensor with shape :math:`(*, D)`.
  
      Examples:
          >>> input = torch.ones(3, 5)
          >>> output = integral_tensor(input, (-2, -1))
          >>> output
          tensor([[ 1.,  2.,  3.,  4.,  5.],
                  [ 2.,  4.,  6.,  8., 10.],
                  [ 3.,  6.,  9., 12., 15.]])
      """
      KORNIA_CHECK_SHAPE(input, ["*", "D"])
  
      if dim is None:
          dim = (-1,)
  
      KORNIA_CHECK(len(dim) > 0, "dim must be a non-empty tuple.")
      KORNIA_CHECK(
          len(dim) <= len(input.shape),
          "dim must be a tuple of length <= input.shape.",
      )
  
      output = input
      for i in dim:
          output = output.cumsum(i)
      return output
  
file_path: kornia/kornia/enhance/integral.py
imports: from typing import Optional, Tuple
  from kornia.core import Module, Tensor
  from kornia.core.check import KORNIA_CHECK, KORNIA_CHECK_SHAPE
label_desc: Use image node_id 1 for calling a global function with example usage: integral_tensor(input, dim) and returns: output