
    3j                    l    S SK Jr  S SKrS SKJr  S	S jrS	S jrS
S jr " S S\R                  5      rg)    )annotationsN)nnc                    [        U R                  5      S:w  a  [        U R                  5      eU S S 2S S 2S S 2S S24   U S S 2S S 2S S 2SS 24   -
  $ N      lenshapeAssertionErrorimgs    T/home/wildlama/miniconda3/lib/python3.13/site-packages/kornia/losses/depth_smooth.py_gradient_xr      sL    
399~SYY''q!Q|s1aAB;///    c                    [        U R                  5      S:w  a  [        U R                  5      eU S S 2S S 2S S2S S 24   U S S 2S S 2SS 2S S 24   -
  $ r   r
   r   s    r   _gradient_yr   !   sL    
399~SYY''q!SbS!|s1aQ;///r   c                2   [        U [        R                  5      (       d  [        S[	        U 5       35      e[        U[        R                  5      (       d  [        S[	        U5       35      e[        U R                  5      S:X  d  [        SU R                   35      e[        UR                  5      S:X  d  [        SUR                   35      eU R                  SS UR                  SS :X  d%  [        SU R                   S	UR                   35      eU R                  UR                  :X  d%  [        S
U R                   S	UR                   35      eU R                  UR                  :X  d%  [        SU R                   S	UR                   35      e[        U 5      n[        U 5      n[        U5      n[        U5      n[        R                  " [        R                  " [        R                  " U5      SSS9* 5      n[        R                  " [        R                  " [        R                  " U5      SSS9* 5      n[        R                  " X&-  5      n[        R                  " X7-  5      n	[        R                  " U5      [        R                  " U	5      -   $ )ad  Criterion that computes image-aware inverse depth smoothness loss.

.. math::

    \text{loss} = \left | \partial_x d_{ij} \right | e^{-\left \|
    \partial_x I_{ij} \right \|} + \left |
    \partial_y d_{ij} \right | e^{-\left \| \partial_y I_{ij} \right \|}

Args:
    idepth: tensor with the inverse depth with shape :math:`(N, 1, H, W)`.
    image: tensor with the input image with shape :math:`(N, 3, H, W)`.

Return:
    a scalar with the computed loss.

Examples:
    >>> idepth = torch.rand(1, 1, 4, 5)
    >>> image = torch.rand(1, 3, 4, 5)
    >>> loss = inverse_depth_smoothness_loss(idepth, image)

z-Input idepth type is not a torch.Tensor. Got z,Input image type is not a torch.Tensor. Got r   z.Invalid idepth shape, we expect BxCxHxW. Got: z-Invalid image shape, we expect BxCxHxW. Got: Nz/idepth and image shapes must be the same. Got: z and z2idepth and image must be in the same device. Got: z1idepth and image must be in the same dtype. Got: r	   T)dimkeepdim)
isinstancetorchTensor	TypeErrortyper   r   
ValueErrordevicedtyper   r   expmeanabs)
idepthimage	idepth_dx	idepth_dyimage_dximage_dy	weights_x	weights_ysmoothness_xsmoothness_ys
             r   inverse_depth_smoothness_lossr.   '   s   , fell++GV~VWWeU\\**FtE{mTUUv||!I&,,XYYu{{q HVWW<<BC 00J6<<.X]^c^i^i]jkll==ELL(Mfmm_\abgbnbnaopqq<<5;;&LV\\NZ_`e`k`k_lmnn *&1I)&1I(/H(/H $iiEIIh4GQX\)](]^I#iiEIIh4GQX\)](]^I "'9+@!AL!&9+@!AL::l#ejj&>>>r   c                  "    \ rS rSrSrSS jrSrg)InverseDepthSmoothnessLossc   a  Criterion that computes image-aware inverse depth smoothness loss.

.. math::

    \text{loss} = \left | \partial_x d_{ij} \right | e^{-\left \|
    \partial_x I_{ij} \right \|} + \left |
    \partial_y d_{ij} \right | e^{-\left \| \partial_y I_{ij} \right \|}

Shape:
    - Inverse Depth: :math:`(N, 1, H, W)`
    - Image: :math:`(N, 3, H, W)`
    - Output: scalar

Examples:
    >>> idepth = torch.rand(1, 1, 4, 5)
    >>> image = torch.rand(1, 3, 4, 5)
    >>> smooth = InverseDepthSmoothnessLoss()
    >>> loss = smooth(idepth, image)

c                    [        X5      $ )N)r.   )selfr$   r%   s      r   forward"InverseDepthSmoothnessLoss.forwardy   s    ,V;;r    Nr$   torch.Tensorr%   r8   returnr8   )__name__
__module____qualname____firstlineno____doc__r4   __static_attributes__r6   r   r   r0   r0   c   s    *<r   r0   )r   r8   r9   r8   r7   )	
__future__r   r   r   r   r   r.   Moduler0   r6   r   r   <module>rB      s0   $ #  009?x< <r   