
    3j                        S SK JrJr  S SKrS SKJr  S SKJrJr  SS\R                  S\\\	S4      S\R                  4S	 jjr
S
\R                  S\R                  4S jr " S S\R                  5      r " S S\R                  5      rg)    )OptionalTupleN)nn)KORNIA_CHECKKORNIA_CHECK_SHAPEinputdim.returnc                     [        U SS/5        Uc  Sn[        [        U5      S:  S5        [        [        U5      [        U R                  5      :*  S5        U nU H  nUR	                  U5      nM     U$ )a  Calculate integral of the input torch.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 torch.Tensor.

Args:
    input: the input torch.Tensor with shape :math:`(*, D)`. Where D is the number of dimensions.
    dim: the dimension to be summed.

Returns:
    Integral torch.Tensor for the input torch.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.]])

*D)r   zdim must be a non-empty tuple.z-dim must be a tuple of length <= input.shape.)r   r   lenshapecumsum)r   r	   outputis       Q/home/wildlama/miniconda3/lib/python3.13/site-packages/kornia/enhance/integral.pyintegral_tensorr      sn    0 usCj)
{SA?@SS--/^_Fq! M    imagec                 6    [        U / SQ5        [        U S5      $ )aP  Calculate integral of the input image torch.Tensor.

This particular version sums over the last two dimensions.

Args:
    image: the input image torch.Tensor with shape :math:`(*, H, W)`.

Returns:
    Integral torch.Tensor for the input image torch.Tensor with shape :math:`(*, H, W)`.

Examples:
    >>> input = torch.ones(1, 5, 5)
    >>> output = integral_image(input)
    >>> output
    tensor([[[ 1.,  2.,  3.,  4.,  5.],
             [ 2.,  4.,  6.,  8., 10.],
             [ 3.,  6.,  9., 12., 15.],
             [ 4.,  8., 12., 16., 20.],
             [ 5., 10., 15., 20., 25.]]])

)r   HW)r   )r   r   )r   s    r   integral_imager   @   s    , uo.5(++r   c                      ^  \ rS rSrSrSS\\\S4      SS4U 4S jjjrS\	R                  S\	R                  4S	 jrS
rU =r$ )IntegralTensor[   a  Calculates integral of the input torch.Tensor.

Args:
    image: the input torch.Tensor with shape :math:`(B,C,H,W)`.

Returns:
    Integral torch.Tensor for the input torch.Tensor with shape :math:`(B,C,H,W)`.

Shape:
    - Input: :math:`(B, C, H, W)`
    - Output: :math:`(B, C, H, W)`

Examples:
    >>> input = torch.ones(3, 5)
    >>> dim = (-2, -1)
    >>> output = IntegralTensor(dim)(input)
    >>> output
    tensor([[ 1.,  2.,  3.,  4.,  5.],
            [ 2.,  4.,  6.,  8., 10.],
            [ 3.,  6.,  9., 12., 15.]])

Nr	   .r
   c                 .   > [         TU ]  5         Xl        g N)super__init__r	   )selfr	   	__class__s     r   r#   IntegralTensor.__init__s   s    r   r   c                 ,    [        XR                  5      $ r!   )r   r	   r$   r   s     r   forwardIntegralTensor.forwardw   s    uhh//r   )r	   r!   )__name__
__module____qualname____firstlineno____doc__r   r   intr#   torchTensorr)   __static_attributes____classcell__)r%   s   @r   r   r   [   sM    .HU38_5   0U\\ 0ell 0 0r   r   c                   R    \ rS rSrSrS\R                  S\R                  4S jrSrg)IntegralImage{   a  Calculates integral of the input image torch.Tensor.

This particular version sums over the last two dimensions.

Args:
    image: the input image torch.Tensor with shape :math:`(B,C,H,W)`.

Returns:
    Integral torch.Tensor for the input image torch.Tensor with shape :math:`(B,C,H,W)`.

Shape:
    - Input: :math:`(B, C, H, W)`
    - Output: :math:`(B, C, H, W)`

Examples:
    >>> input = torch.ones(1, 5, 5)
    >>> output = IntegralImage()(input)
    >>> output
    tensor([[[ 1.,  2.,  3.,  4.,  5.],
             [ 2.,  4.,  6.,  8., 10.],
             [ 3.,  6.,  9., 12., 15.],
             [ 4.,  8., 12., 16., 20.],
             [ 5., 10., 15., 20., 25.]]])

r   r
   c                     [        U5      $ r!   )r   r(   s     r   r)   IntegralImage.forward   s    e$$r    N)	r+   r,   r-   r.   r/   r1   r2   r)   r3   r:   r   r   r6   r6   {   s"    4%U\\ %ell %r   r6   r!   )typingr   r   r1   r   kornia.core.checkr   r   r2   r0   r   r   Moduler   r6   r:   r   r   <module>r>      s   $ #   >#5<< #huS#X.G #SXS_S_ #L,%,, ,5<< ,60RYY 0@%BII %r   