
    3j                       S SK Jr  S SKJr  S SKrS SKJs  Jr  S SKJr  S SK	J
r
Jr  S SKJrJr  SSKJrJr  SS	KJr  \R(                  " / S
Q\R*                  S9r\R(                  " / SQ\R*                  S9r\R(                  " / SQ\R*                  S9rS$S%S jjrS$S%S jjrS$S&S jjrS$S&S jjr " S S\R:                  5      r " S S\R:                  5      r       S'                 S(S jjr         S)                   S*S jjr! S+       S,S jjr" " S S\R:                  5      r# S-                     S.S jjr$      S/               S0S jjr% " S S\R:                  5      r&      S1               S2S jjr' " S  S!\R:                  5      r( " S" S#\R:                  5      r)g)3    )annotations)OptionalN)nn)normalize_pixel_coordinatesnormalize_pixel_coordinates3d)create_meshgridcreate_meshgrid3d   )spatial_expectation2dspatial_softmax2d)nms3d)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r
   r
   r
   r
   r
   r
   r
   r
   r
   )dtype)r   r   r   r   r   r   r
   r
   r
   r   r   r   r   r   r   r
   r
   r
   r   r   r   r   r   r   r
   r
   r
   )r   r   r
   r   r   r
   r   r   r
   r   r   r
   r   r   r
   r   r   r
   r   r   r
   r   r   r
   r   r   r
   c                    Uc  [         R                  " S5      n[        XSUS9n[        X0U5      nUR	                  SSSS5      nU$ )zGenerate a kernel to with window coordinates, residual to window center.

Args:
     h: kernel height.
     w: kernel width.
     device: device, on which generate.

Returns:
    conv_kernel [2x1xhxw]

cpuFdevice   r   r
      )torchr   r   r   permute)hwr   window_grid2dconv_kernels        d/home/wildlama/miniconda3/lib/python3.13/site-packages/kornia/geometry/subpix/spatial_soft_argmax.py_get_window_grid_kernel2dr   2   sM     ~e$#A%?M/!DM''1a3K    c                >   Uc  [         R                  " S5      n[         R                  " SSXUS9nU S-  S:w  a  U S-  nU S-  S-   nOU S-  S-
  nU S-  S-   nUS-  S:w  a  US-  nUS-  S-   nOUS-  S-
  nUS-  S-   nS[        XT-
  Xv-
  -  5      -  USSXE2Xg24'   U$ )zGenerate a kernel to return center coordinates, when applied with F.conv2d to 2d coordinates grid.

Args:
    h: kernel height.
    w: kernel width.
    device: device, on which generate.

Returns:
    conv_kernel [2x2xhxw].

r   r   r   r   r
         ?)r   r
   r   r   zerosfloat)r   r   r   center_kernelh_i1h_i2w_i1w_i2s           r   _get_center_kernel2dr)   F   s     ~e$KK1a6:M 	1uzAvQ!|Q!|Q!|1uzAvQ!|Q!|Q!|:=t{W[WbFc@d:dM&&$)TY67r   c           	        Uc  [         R                  " S5        [         R                  " SSXX#S9nUS-  S:w  a  US-  nUS-  S-   nOUS-  S-
  nUS-  S-   nUS-  S:w  a  US-  nUS-  S-   nOUS-  S-
  nUS-  S-   nU S-  S:w  a  U S-  n	U S-  S-   n
OU S-  S-
  n	U S-  S-   n
[        Xe-
  X-
  -  X-
  -  5      nSU-  USSX2XV2Xx24'   U$ )	zGenerate a kernel to return center coordinates, when applied with F.conv2d to 3d coordinates grid.

Args:
    d: kernel depth.
    h: kernel height.
    w: kernel width.
    device: device, on which generate.

Returns:
    conv_kernel [3x3xdxhxw].

r   r   r   r   r   r
   r    )r   r
   r   r!   )dr   r   r   r$   r%   r&   r'   r(   d_i1d_i2
center_nums               r   _get_center_kernel3dr/   g   s    ~UKK1aA=M1uzAvQ!|Q!|Q!|1uzAvQ!|Q!|Q!|1uzAvQ!|Q!|Q!|4DEJKNQ[K[M)Y	49diGHr   c           	        Uc  [         R                  " S5      n[        XSUS9nU S:  a)  [         R                  " SSXS9R	                  U SSS5      nO[         R
                  " SSSSUS9n[         R                  " UR                  SXS5      R                  5       UR                  U SSS5      /S5      nUR                  SSSS5      R                  S5      nU$ )	zGenerate a kernel to return coordinates, residual to window center.

Args:
    d: kernel depth.
    h: kernel height.
    w: kernel width.
    device: device, on which generate.

Returns:
    conv_kernel [3x1xdxhxw]

r   Tr   r
   r   r   r   r   )r   r   r   linspaceviewr"   catrepeat
contiguousr   	unsqueeze)r+   r   r   r   grid2dzgrid3dr   s           r   _get_window_grid_kernel3dr:      s     ~e$Q47F1uNN2q!388Aq!DKK1a62YYA!,7796==AqRS;TUWXYF..Aq!,66q9Kr   c                  t   ^  \ rS rSrSr       S               SU 4S jjjrS	S jrS
S jrSrU =r	$ )ConvSoftArgmax2d   z{nn.Module that calculates soft argmax 2d per window.

See
:func: `~kornia.geometry.subpix.conv_soft_argmax2d` for details.
c                v   > [         TU ]  5         Xl        X l        X0l        X@l        XPl        X`l        Xpl        g N)	super__init__kernel_sizestridepaddingtemperaturenormalized_coordinatesepsoutput_value)	selfrB   rC   rD   rE   rF   rG   rH   	__class__s	           r   rA   ConvSoftArgmax2d.__init__   s7     	&&&<#(r   c                    U R                   R                   SU R                   SU R                   SU R                   SU R
                   SU R                   SU R                   SU R                   S3$ )	N(kernel_size=	, stride=
, padding=, temperature=, normalized_coordinates=, eps=, output_value=))	rJ   __name__rB   rC   rD   rE   rF   rG   rH   rI   s    r   __repr__ConvSoftArgmax2d.__repr__   s    ~~&&'D,,- .kk] #||n %++, -&&*&A&A%B C88*  --.a1		
r   c           
         [        UU R                  U R                  U R                  U R                  U R
                  U R                  U R                  5      $ r?   )conv_soft_argmax2drB   rC   rD   rE   rF   rG   rH   rI   xs     r   forwardConvSoftArgmax2d.forward   sK    !KKLL''HH	
 		
r   )rG   rB   rF   rH   rD   rC   rE   )r   r   r
   r
   r`   r    T:0yE>F)rB   tuple[int, int]rC   rb   rD   rb   rE   torch.Tensor | floatrF   boolrG   r#   rH   rd   returnNonere   strr\   torch.Tensorre   0torch.Tensor | tuple[torch.Tensor, torch.Tensor]
rU   
__module____qualname____firstlineno____doc__rA   rW   r]   __static_attributes____classcell__rJ   s   @r   r<   r<      s     (."(#),/'+")$)  ) !	)
 *) !%) ) ) 
) )&



 

r   r<   c                  z   ^  \ rS rSrSr        S                 SU 4S jjjrS	S jrS
S jrSrU =r	$ )ConvSoftArgmax3d   z{nn.Module that calculates soft argmax 3d per window.

See
:func: `~kornia.geometry.subpix.conv_soft_argmax3d` for details.
c	                   > [         T	U ]  5         Xl        X l        X0l        X@l        XPl        X`l        Xpl        Xl	        g r?   )
r@   rA   rB   rC   rD   rE   rF   rG   rH   strict_maxima_bonus)
rI   rB   rC   rD   rE   rF   rG   rH   rx   rJ   s
            r   rA   ConvSoftArgmax3d.__init__   s=     	&&&<#(#6 r   c                   U R                   R                   SU R                   SU R                   SU R                   SU R
                   SU R                   SU R                   SU R                   SU R                   S	3$ )
NrM   rN   rO   rP   rQ   rR   , strict_maxima_bonus=rS   rT   )
rJ   rU   rB   rC   rD   rE   rF   rG   rx   rH   rV   s    r   rW   ConvSoftArgmax3d.__repr__   s    ~~&&'D,,- .kk] #||n %++, -&&*&A&A%B C88* ##'#;#;"< = --.a1
	
r   c                    [        UU R                  U R                  U R                  U R                  U R
                  U R                  U R                  U R                  5	      $ r?   )	conv_soft_argmax3drB   rC   rD   rE   rF   rG   rH   rx   r[   s     r   r]   ConvSoftArgmax3d.forward  sT    !KKLL''HH$$

 
	
r   )rG   rB   rF   rH   rD   rx   rC   rE   r   r   r   r
   r
   r
   r   r    Fra   Tg        )rB   tuple[int, int, int]rC   r   rD   r   rE   rc   rF   rd   rG   r#   rH   rd   rx   r#   re   rf   rg   ri   rl   rs   s   @r   ru   ru      s     -6'0(1,/',!%(7)7 %7 &	7
 *7 !%7 7 7 #7 
7 7*

 
r   ru   c           	     *   [         R                  " U 5      (       d  [        S[        U 5       35      e[	        U R
                  5      S:X  d  [        SU R
                   35      eUS::  a  [        SU 35      eU R
                  u  ppUu  pU R                  nU R                  nU R                  X-  SX5      n [        XU5      R                  U5      n[        XU5      R                  U5      nU R                  SSS	9nU UR                  5       -
  U-  R                  5       n[!        X-  5      nU["        R$                  " UXUS
9-  U-   nU["        R$                  " UU -  XUS
9-  U-  nUR                  XUR'                  S5      UR'                  S5      5      n[)        XSU5      R                  U5      R+                  SSSS5      n["        R,                  " UUX#S
9n["        R,                  " UUX#S
9nUUR/                  U5      -  nUUR/                  U5      -   nU(       a2  [1        UR+                  SSSS5      X5      nUR+                  SSSS5      nUR                  XSUR'                  S5      UR'                  S5      5      nU(       a  UU4$ U$ )a&  Compute the convolutional spatial Soft-Argmax 2D over the windows of a given heatmap.

.. math::
    ij(X) = \frac{\sum{(i,j)} * exp(x / T)  \in X} {\sum{exp(x / T)  \in X}}

.. math::
    val(X) = \frac{\sum{x * exp(x / T)  \in X}} {\sum{exp(x / T)  \in X}}

where :math:`T` is temperature.

Args:
    input: the given heatmap with shape :math:`(N, C, H_{in}, W_{in})`.
    kernel_size: the size of the window.
    stride: the stride of the window.
    padding: input zero padding.
    temperature: factor to apply to input.
    normalized_coordinates: whether to return the coordinates normalized in the range of :math:`[-1, 1]`.
        Otherwise, it will return the coordinates in the range of the input shape.
    eps: small value to avoid zero division.
    output_value: if True, val is output, if False, only ij.

Returns:
    Function has two outputs - argmax coordinates and the softmaxpooled heatmap values themselves.
    On each window, the function computed returns with shapes :math:`(N, C, 2, H_{out},
    W_{out})`, :math:`(N, C, H_{out}, W_{out})`,

    where

     .. math::
         H_{out} = \left\lfloor\frac{H_{in}  + 2 \times \text{padding}[0] -
           (\text{kernel\_size}[0] - 1) - 1}{\text{stride}[0]} + 1\right\rfloor

     .. math::
         W_{out} = \left\lfloor\frac{W_{in}  + 2 \times \text{padding}[1] -
           (\text{kernel\_size}[1] - 1) - 1}{\text{stride}[1]} + 1\right\rfloor

Examples:
    >>> input = torch.randn(20, 16, 50, 32)
    >>> nms_coords, nms_val = conv_soft_argmax2d(input, (3,3), (2,2), (1,1), output_value=True)

&Input type is not a torch.Tensor. Got    z-Invalid input shape, we expect BxCxHxW. Got: r   ;Temperature should be positive float or torch.Tensor. Got: r
   )r   TdimkeepdimrC   rD   r   r   F)r   	is_tensor	TypeErrortypelenshape
ValueErrorr   r   r2   r)   tor   amaxdetachexpr#   F
avg_pool2dsizer   r   conv2d	expand_asr   )inputrB   rC   rD   rE   rF   rG   rH   bcr   r   kykxr   r   r$   window_kernelx_maxx_exp	pool_coefdenx_softmaxpoolgrid_globalgrid_global_pooled
coords_maxs                             r   rZ   rZ     sz   f ??5!!@eNOOu{{q HVWWaVWbVcdeeJA!FB <<FEJJqua&E"6rv"F"I"I%"PM";BF"K"N"Nu"UM
 JJ8TJ2E elln$388:E RW~I all5+gV
VY\
\CUU]K`g hhknnM!&&q]-?-?-BMDVDVWXDYZM !0eV D G G N V VWXZ[]^`a bK+}V]  !xx}V]JcmmJ77J0:::FFJ 01C1CAq!Q1OQRV
''1a3
 q*//!*<jooa>PQJ=((r   c	           
        [         R                  " U 5      (       d  [        S[        U 5       35      e[	        U R
                  5      S:X  d  [        SU R
                   35      eUS::  a  [        SU 35      eU R
                  u  ppnUu  pnU R                  nU R                  nU R                  X-  SXU5      n [        XUU5      R                  U5      n[        XUU5      R                  U5      nU R                  SSS	9nU UR                  5       -
  U-  R                  5       n[!        UU-  U-  5      nU["        R$                  " UR'                  U 5      XUS
9-  U-   n[)        XUSUS9R                  U5      R+                  SSSSS5      n["        R,                  " UUX#S
9n["        R,                  " UUX#S
9nUUR/                  U5      -  nUUR/                  U5      -   nU(       a5  [1        UR+                  SSSSS5      XU5      nUR+                  SSSSS5      nUR                  XSUR3                  S5      UR3                  S5      UR3                  S5      5      nU(       d  U$ U["        R$                  " UR                  U R3                  5       5      U -  XUS
9-  U-  nUS:  ah  U R3                  S5      nUR3                  S5      nUU-
  S-  n["        R$                  " [5        X5      SUS5      n U SS2SS2UUU-
  24   n USUU -  -   -  nUR                  XUR3                  S5      UR3                  S5      UR3                  S5      5      nUU4$ )a  Compute the convolutional spatial Soft-Argmax 3D over the windows of a given heatmap.

.. math::
         ijk(X) = \frac{\sum{(i,j,k)} * exp(x / T)  \in X} {\sum{exp(x / T)  \in X}}

.. math::
         val(X) = \frac{\sum{x * exp(x / T)  \in X}} {\sum{exp(x / T)  \in X}}

where ``T`` is temperature.

Args:
    input: the given heatmap with shape :math:`(N, C, D_{in}, H_{in}, W_{in})`.
    kernel_size:  size of the window.
    stride: stride of the window.
    padding: input zero padding.
    temperature: factor to apply to input.
    normalized_coordinates: whether to return the coordinates normalized in the range of :math:[-1, 1]`.
        Otherwise, it will return the coordinates in the range of the input shape.
    eps: small value to avoid zero division.
    output_value: if True, val is output, if False, only ij.
    strict_maxima_bonus: pixels, which are strict maxima will score (1 + strict_maxima_bonus) * value.
      This is needed for mimic behavior of strict NMS in classic local features

Returns:
    Function has two outputs - argmax coordinates and the softmaxpooled heatmap values themselves.
    On each window, the function computed returns with shapes :math:`(N, C, 3, D_{out}, H_{out}, W_{out})`,
    :math:`(N, C, D_{out}, H_{out}, W_{out})`,

    where

     .. math::
         D_{out} = \left\lfloor\frac{D_{in}  + 2 \times \text{padding}[0] -
         (\text{kernel\_size}[0] - 1) - 1}{\text{stride}[0]} + 1\right\rfloor

     .. math::
         H_{out} = \left\lfloor\frac{H_{in}  + 2 \times \text{padding}[1] -
         (\text{kernel\_size}[1] - 1) - 1}{\text{stride}[1]} + 1\right\rfloor

     .. math::
         W_{out} = \left\lfloor\frac{W_{in}  + 2 \times \text{padding}[2] -
         (\text{kernel\_size}[2] - 1) - 1}{\text{stride}[2]} + 1\right\rfloor

Examples:
    >>> input = torch.randn(20, 16, 3, 50, 32)
    >>> nms_coords, nms_val = conv_soft_argmax3d(input, (3, 3, 3), (1, 2, 2), (0, 1, 1))

r      z/Invalid input shape, we expect BxCxDxHxW. Got: r   r   r
   )r   r   Tr   r   Fr   r   r   r   Nr    )r   r   r   r   r   r   r   r   r   r2   r/   r   r:   r   r   r   r#   r   
avg_pool3dview_asr	   r   conv3dr   r   r   r   )!r   rB   rC   rD   rE   rF   rG   rH   rx   r   r   r+   r   r   kzr   r   r   r   r$   r   r   r   r   r   r   r   r   r   	in_levels
out_levelsskip_levelsstrict_maximas!                                    r   r~   r~     sV   t ??5!!@eNOOu{{q J5;;-XYYaVWbVcdeeKKMA!JBB <<FEJJquaq)E"6rr6"J"M"Me"TM";BB"O"R"RSX"YM
 JJ<J6E elln$388:ER"Wr\*I all5==#7]de
ehk
kC !2!5 P S STY Z b bcdfgijlmop qK+}V]  !xx}V]JcmmJ77J0:::FFJ
 2:3E3EaAqRS3TVW\]^
''1aA6
 q*//!*<jooa>PR\RaRabcRdeJ 	ALLEJJL!9E!A;gnooruu  QA	',,Q/
%
2q8&'ll53LaQWYZ&[%aK*{:R,R&RS2]BBB!&&q]-?-?-BMDVDVWXDY[h[m[mno[pqM}$$r   c                d    Uc  [         R                  " S5      n[        X5      n[        X25      nU$ )a  Compute the Spatial Soft-Argmax 2D of a given input heatmap.

Args:
    input: the given heatmap with shape :math:`(B, N, H, W)`.
    temperature: factor to apply to input.
    normalized_coordinates: whether to return the coordinates normalized in the range of :math:`[-1, 1]`.
        Otherwise, it will return the coordinates in the range of the input shape.

Returns:
    the index of the maximum 2d coordinates of the give map :math:`(B, N, 2)`.
    The output order is x-coord and y-coord.

Examples:
    >>> input = torch.tensor([[[
    ... [0., 0., 0.],
    ... [0., 10., 0.],
    ... [0., 0., 0.]]]])
    >>> spatial_soft_argmax2d(input, normalized_coordinates=False)
    tensor([[[1.0000, 1.0000]]])

r    )r   tensorr   r   )r   rE   rF   
input_softoutputs        r   spatial_soft_argmax2dr     s1    0 ll3'0DJ0TFMr   c                  H   ^  \ rS rSrSrSSU 4S jjjrS	S jrS
S jrSrU =r	$ )SpatialSoftArgmax2di$  zCompute the Spatial Soft-Argmax 2D of a given heatmap.

See :func:`~kornia.geometry.subpix.spatial_soft_argmax2d` for details.
c                l   > [         TU ]  5         Uc  [        R                  " S5      nXl        X l        g )Nr    )r@   rA   r   r   rE   rF   )rI   rE   rF   rJ   s      r   rA   SpatialSoftArgmax2d.__init__*  s.    ,,s+K)4,B#r   c                h    U R                   R                   SU R                   SU R                   S3$ )Nztemperature=rQ   rT   )rJ   rU   rE   rF   rV   s    r   rW   SpatialSoftArgmax2d.__repr__1  s>    ~~&&'4++, -&&*&A&A%B!E	
r   c                B    [        XR                  U R                  5      $ r?   )r   rE   rF   )rI   r   s     r   r]   SpatialSoftArgmax2d.forward8  s    $U,<,<d>Y>YZZr   )rF   rE   NT)rE   Optional[torch.Tensor]rF   rd   re   rf   rg   )r   rj   re   rj   rl   rs   s   @r   r   r   $  s%    
C C
[ [r   r   c
                   X-  XU-  -
  n
X2-  XT-  -
  nX5-  X-  -
  nX
-  X;-  -
  XL-  -   nUR                  5       U	:  n[        R                  " X[        R                  " U5      5      nXj-  X7U-  XX-  -
  -  -
  XGU-  X-  -
  -  -   U-  nXU-  XX-  -
  -  Xk-  -
  XCU-  Xt-  -
  -  -   U-  nXU-  Xu-  -
  -  X3U-  Xt-  -
  -  -
  Xl-  -   U-  nUUUU4$ )u  Solve H * [sx, sy, ss]^T = [r0, r1, r2]^T via Cramer's rule.

H is symmetric: H = [[dxx, dxy, dxs], [dxy, dyy, dys], [dxs, dys, dss]].
All inputs are batched 1-D tensors of length N.

Args:
    dxx: diagonal Hessian element (d²/dx²).
    dyy: diagonal Hessian element (d²/dy²).
    dss: diagonal Hessian element (d²/ds²).
    dxy: off-diagonal Hessian element (d²/dxdy).
    dxs: off-diagonal Hessian element (d²/dxds).
    dys: off-diagonal Hessian element (d²/dyds).
    r0: right-hand side component along x.
    r1: right-hand side component along y.
    r2: right-hand side component along s.
    eps: determinant magnitude below which the system is treated as singular.
        Near-singular systems can produce numerically unstable (huge) shifts.

Returns:
    (sx, sy, ss, solved) where ``solved`` is a bool mask for well-conditioned
    systems (``|det| > eps``).  Outputs for unsolved entries are numerically
    meaningless and should be discarded by the caller.
)absr   where	ones_like)dxxdyydssdxydxsdysr0r1r2rG   cf00cf01cf02detsolvedsafe_detsxsysss                      r   _solve_cramer_sym3x3r   <  s   F 9sy D9sy D9sy D
*sz
!CJ
.CWWY_F{{6(<=H
)c#X01
1C8ch;N4O
OS[	[B
cCH$
%	
1C8bh;N4O
OS[	[B
rBH$
%Rx"(/B(C
Cbi
OS[	[Br2vr   c                   [         R                  " U 5      (       d  [        S[        U 5       35      eU R                  S:w  a  [        SU R                   35      eU R                  u  pxpnU R                  nU R                  nXx-  nX-  U-  nX-  n[         R                  " XxSXXUS9n[         R                  " XUS9R                  U	SS5      USS2SS2S4'   [         R                  " XUS9R                  SSU5      USS2SS2S4'   [         R                  " XUS9R                  SU
S5      USS2SS2S	4'   U R                  5       nU	S:  d  U
S:  d  US:  a  UU4$ Ub  UO[        U S
S5      n[         R                  " UR                  XX5      5      u  nnnnUR                  S   nUn[         R                  " U* US-   U[         R                  S9n[         R                   " UUUSS9u  nnnUR#                  S5      nUR#                  S5      nUR#                  S5      nUR                  S   nUR%                  S5      UR%                  S5      -   R#                  S5      nUR%                  S5      UR%                  S5      -   R#                  S5      n UR%                  S5      UR%                  S5      -   R#                  S5      n!UR%                  S5      R'                  SU5      R#                  S5      n"US:  UU	S	-
  :*  -  U S:  -  U U
S	-
  :*  -  U!S:  -  U!US	-
  :*  -  n#U"U#   n$UU#   n%U U#   n&U!U#   n'U R                  S5      n([(        R+                  U5      U-  [,        R+                  U5      U-  -   [.        R+                  U5      -   n)U$U-  U%U-  -   U&U-  -   U'-   n*U(U*R%                  S5      U)R%                  S5      -      n+U+SS2S4   n,U+SS2S4   n-U+SS2S4   n.U+SS2S4   n/U+SS2S4   n0U+SS2S4   n1U+SS2S4   n2U+SS2S4   n3U+SS2S4   n4U+SS2S4   n5U+SS2S4   n6U+SS2S4   n7U+SS2S4   n8U+SS2S4   n9U+SS2S4   n:U+SS2S4   n;U+SS2S4   n<U+SS2S4   n=U+SS2S4   n>SU.U--
  -  n?SU0U/-
  -  n@SU2U1-
  -  nAU.S U,-  -
  U--   nBU0S U,-  -
  U/-   nCU2S U,-  -
  U1-   nDS!U6U5-
  U4-
  U3-   -  nES!U:U9-
  U8-
  U7-   -  nFS!U>U=-
  U<-
  U;-   -  nG[1        UBUCUDUEUFUGU?* U@* UA* 5	      u  nHnInJnKU?UH-  U@UI-  -   UAUJ-  -   nLU$R                  S   nM[         R2                  " X-  4S[         R4                  US"9nN[         R                  " UM[         R4                  US"9UNU$U-  U%U-  -   U&U-  -   U'-   '   UR                  5       nOUR                  5       nPUR                  5       nQ[         R6                  " U[         R8                  US"9nR[         R:                  " UXS9nS[         R:                  " UXS9nT[         R:                  " UXS9nU[         R:                  " UXS9nV[=        U5       GH:  nWWOR?                  SU	S	-
  5      nXWPR?                  SU
S	-
  5      nYWQR?                  SUS	-
  5      nZUU-  UXU-  -   UYU-  -   UZ-   n[WNU[   R                  5       n\U\S:  n]U\R?                  SS#9n^WHU^   n_WIU^   n`WJU^   naWLU^   nbWKU^   U]-  ncWRUc-  nRURR+                  U5      ndU_Ud-  n_U`Ud-  n`UaUd-  na[         R                  " URU_WS5      nS[         R                  " URU`WT5      nT[         R                  " URUaWU5      nU[         R                  " URUbWV5      nVURU_U:  -  neURU_U* :  -  nfUQUeR                  5       -   UfR                  5       -
  ngURUgS:  -  UgUS	-
  :*  -  nRUgR?                  SUS-
  5      nQURU`U:  -  nhURU`U* :  -  niUPUhR                  5       -   UiR                  5       -
  njURUjS:  -  UjU
S	-
  :*  -  nRUjR?                  SU
S-
  5      nPU(       d  GM  WRWaU:  -  nkURUaU* :  -  nlWOUkR                  5       -   UlR                  5       -
  nmURUmS:  -  UmU	S	-
  :*  -  nRUmR?                  SU	S-
  5      nOGM=     WRWSRA                  5       S$:*  -  WTRA                  5       S$:*  -  WURA                  5       S$:*  -  nRUU-  nnUU-  no[         R                  " URWOR+                  U5      UU-   UR+                  U5      5      UUnUoSUUU4'   [         R                  " URWQR+                  U5      US-   UR+                  U5      5      UUnUoSUUU4'   [         R                  " URWPR+                  U5      UT-   UR+                  U5      5      UUnUoS	UUU4'   S[         R                  " URWV[         RB                  " UV5      5      -  npU R                  XX5      UUOUPUQ4   nqUqUp-   UUnUoUUU4'   US:  a$  UWnWoUUU4==   UWRR+                  U5      -  -  ss'   UU4$ )%u  Subpixel localization of 3D scale-space extrema via quadratic interpolation.

For each NMS maximum the function fits a 3-D quadratic to the local
:math:`3 \times 3 \times 3` neighbourhood and solves for the sub-voxel
shift that maximises the fit.  When the shift along any axis exceeds
``max_subpixel_shift`` the integer centre is moved one step in that direction
and the solve is repeated — up to ``n_iters`` times.

Unlike a naive iterative approach, all Hessian solves are precomputed once at
the start for every voxel that any keypoint could possibly visit (the
**dilated NMS neighbourhood**, an L\ :math:`\infty` ball of radius
``dilation_radius`` around each maximum).  The subsequent iteration loop contains
**no data-dependent Python control flow** and no GPU→CPU synchronisation,
making the function fully compatible with ``torch.compile`` / CUDA graphs.

The ``dilation_radius`` controls the precompute footprint and should be set
to the maximum number of integer-centre moves expected per keypoint.  With the
default ``max_subpixel_shift=0.6`` almost all keypoints converge within 1 move,
so the default ``dilation_radius=1`` (i.e. :math:`3^3 = 27` positions per
maximum) is sufficient.  Use ``dilation_radius=2`` (:math:`5^3 = 125`) for
extra safety.  Setting it equal to ``n_iters`` recovers the original behaviour
but is much slower on large images.

Args:
    input: response pyramid with shape :math:`(B, C, D, H, W)`.
    n_iters: maximum number of localization iterations per keypoint.
    strict_maxima_bonus: value added to ``y_max`` at NMS-maximum positions
        so that strict maxima are preferred during top-K selection.
    max_subpixel_shift: threshold above which the integer centre is
        moved one step and another iteration is run.
    precomputed_nms_mask: optional bool tensor of shape
        :math:`(B, C, D, H, W)` — pass the result of
        :func:`~kornia.geometry.subpix.nms3d` to skip the internal NMS call.
    dilation_radius: L\ :math:`\infty` radius (in voxels) of the neighbourhood
        around each NMS maximum where the Hessian solve is precomputed.
        Keypoints that attempt to move farther than this are marked invalid.
    allow_scale_steps: if ``True`` (default), the iterative shift is also
        applied along the scale (depth) axis; set to ``False`` to keep the
        keypoint on its original scale level.

Returns:
    Tuple ``(coords_max, y_max)``:

    * ``coords_max`` — shape :math:`(B, C, 3, D, H, W)`, refined
      ``[scale, x(width), y(height)]`` coordinates for each NMS maximum;
      non-maximum positions keep their grid coordinates.
    * ``y_max`` — shape :math:`(B, C, D, H, W)`, quadratically corrected
      response with optional strict-maxima bonus.

Example:
    >>> input = torch.randn(2, 3, 5, 64, 64)
    >>> coords, vals = conv_quad_interp3d(input, n_iters=5)
    >>> coords.shape
    torch.Size([2, 3, 3, 5, 64, 64])
    >>> vals.shape
    torch.Size([2, 3, 5, 64, 64])

r   r   .Invalid input shape, expected BxCxDxHxW. Got: r   r   r   r
   Nr   r   r   Tij)indexingr            
      r      	                                 ?       @      ?r   r   )min      ?)"r   r   r   r   ndimr   r   r   r   emptyaranger2   cloner   r   longmeshgridreshaper6   expand	_PATCH_DDr   	_PATCH_DH	_PATCH_DWr   fullint32onesrd   r"   rangeclampr   
zeros_like)rr   n_itersrx   max_subpixel_shiftprecomputed_nms_maskdilation_radiusallow_scale_stepsBCDHWr   r   BCDHWHWr   y_maxnms_maskbc_idxd_idxh_idxw_idxNroffsodohowKd_dilh_dilw_dilbc_dilkeepbc_ud_uh_uw_uinp_flatpatch_offsetscenter_flatpatchc000p_xmp_xpp_ymp_ypp_smp_spp_xm_ymp_xp_ymp_xm_ypp_xp_ypp_xm_smp_xp_smp_xm_spp_xp_spp_ym_smp_yp_smp_ym_spp_yp_spgxgygsr   r   r   r   r   r   sx_usy_uss_usol_ugds_uNKlutd_curh_curw_curvalidshift_xshift_yshift_sgrad_dot_shift_dihiwiflat_qlut_idxin_lutidx_safer   r   r   gdssolvfmove_pxmove_nxnew_wmove_pymove_nynew_hmove_psmove_nsnew_db_idxc_idxval_correction
val_centersr                                                                                                                     r   conv_quad_interp3drj  l  s
   F ??5!!@eNOOzzQI%++WXXKKMA!\\FKKE	
B
%!)C	
BQ1aAEJJ,,quEJJ1aQRSJq!Qw,,quEJJ1aQRSJq!Qw,,quEJJ1aQRSJq!QwKKME1uAQ5   (<'G#USXZceiMjH"'++hmmB1.H"IFE5%QA 	A<<AE&

CDdD4@JBB	BB	BB	BB
A __Q",,q/1::2>E__Q",,q/1::2>E__Q",,q/1::2>Ea ''A.66r:F QJ5AE>*eqj9Ua!e^LPUYZPZ[_dhilmhm_mnD$<D
+C
+C
+C zz"~HLL(2-	V0Dq0HH9<<X^K__M*sRx'#'1C7K[**1-0G0G0JJKE B<DB<DB<DB<DB<DA;DB<DAqDkGArElGArElGArElGAqDkGAqDkGArElGArElGAqDkGAqDkGArElGArElG 
t	B	t	B	t	B
t
d
"C
t
d
"C
t
d
"C
'G#g-7
8C
'G#g-7
8C
'G#g-7
8C23S#sCRTQTWYVY\^[^_D$eIT	!BI-E 
AB
**bh["EKK
GC16b\b1cCs
S2Xa'#-. KKMEKKMEKKMEJJq

6:Ekk!F8Gkk!F8Gkk!F8G[[6?N7^[[AE"[[AE"[[AE"#R'"q&025f+""$A==Q='(^(^(^HoHo&XXe_"W"W"W++eR1++eR1++eR1UC@2 2232!3 334&7!$Q7Aq1u%2 2232!3 334&7!$Q7Aq1u%r$667Gr%7$778GGLLN*W\\^;EUaZ(EQUN;EKK1q5)EY \ W[[]c)*gkkms.BCw{{}X[G[\E aKEQJE7<{{5%((SX/\cJcejememnset7uJueQue347<{{5%((SX/\cJcejememnset7uJueQue347<{{5%((SX/\cJcejememnset7uJueQue345;;une>N>N~>^__NB1(u)DEJ/9N/JE%ue
+,QeUE5%/04G%((SX/4YY0ur   c                  x   ^  \ rS rSrSr     S           SU 4S jjjrS	S jr S
     SS jjrSrU =r	$ )ConvQuadInterp3dip  ut  Subpixel localization of 3D scale-space extrema via quadratic interpolation.

Wraps :func:`~kornia.geometry.subpix.conv_quad_interp3d`.  The Hessian system
is solved once for each voxel in the dilated NMS neighbourhood (no dense
precomputation over the whole volume), then the shift chain is followed by
table lookup with no GPU→CPU synchronisation — making the module compatible
with ``torch.compile`` and CUDA graphs.

Args:
    n_iters: maximum localization iterations per keypoint.
    strict_maxima_bonus: score bonus at NMS-maximum positions.
    max_subpixel_shift: shift threshold that triggers integer centre move.
c                ^   > [         TU ]  5         Xl        X l        X0l        X@l        XPl        g r?   )r@   rA   r  rx   r  r	  r
  )rI   r  rx   r  r	  r
  rJ   s         r   rA   ConvQuadInterp3d.__init__  s-     	#6 "4.!2r   c                    U R                   R                   SU R                   SU R                   SU R                   SU R
                   SU R                   S3$ )N	(n_iters=r{   , max_subpixel_shift=, dilation_radius=, allow_scale_steps=rT   )rJ   rU   r  rx   r  r	  r
  rV   s    r   rW   ConvQuadInterp3d.__repr__  sp    ~~&&' (||n %##'#;#;"< =""&"9"9!: ;#334 5!!%!7!7 8;	
r   c           	         [        UU R                  U R                  U R                  UU R                  U R
                  5      $ r?   )rj  r  rx   r  r	  r
  rI   r\   r  s      r   r]   ConvQuadInterp3d.forward  sB     "LL$$##   ""
 	
r   )r
  r	  r  r  rx   )r         $@333333?r
   T)r  intrx   r#   r  r#   r	  rz  r
  rd   re   rf   rg   r?   r\   rj   r  r   re   !tuple[torch.Tensor, torch.Tensor]rl   rs   s   @r   rl  rl  p  s      %)$' "&33 #3 "	3
 3  3 
3 3
 OS

5K
	*
 
r   rl  c                   [         R                  " U 5      (       d  [        S[        U 5       35      eU R                  S:w  a  [        SU R                   35      eU R                  u  pxpnU R                  nU R                  n[         R                  " XxSXXUS9n[         R                  " XUS9R                  U	SS5      USS2SS2S4'   [         R                  " XUS9R                  SSU5      USS2SS2S4'   [         R                  " XUS9R                  SU
S5      USS2SS2S	4'   U R                  5       nU	S:  d  U
S:  d  US:  a  X4$ U R                  Xx-  XU5      nX-  U-  nX-  nUb  UO[        U S
S5      R                  Xx-  XU5      n[         R                  " U5      u  nnnnUR                  S   nUb=  UU:  a7  UUUUU4   n[         R                   " UUS9u  nnUU   nUU   nUU   nUU   nUn["        R%                  U5      U-  [&        R%                  U5      U-  -   [(        R%                  U5      -   nUR                  5       nUR                  5       nUR                  5       n[         R*                  " U[         R,                  US9n [         R.                  " UXS9n![         R.                  " UXS9n"[         R.                  " UXS9n#[         R.                  " UXS9n$UR                  S5      n%UU-  n&[1        U5       GHP  nUR3                  SU	S	-
  5      n'UR3                  SU
S	-
  5      n(UR3                  SUS	-
  5      n)U%U&U'U-  -   U(U-  -   U)-   R5                  S5      UR5                  S5      -      n*U*SS2S4   n+U*SS2S4   n,U*SS2S4   n-U*SS2S4   n.U*SS2S4   n/U*SS2S4   n0U*SS2S4   n1U*SS2S4   n2U*SS2S4   n3U*SS2S4   n4U*SS2S4   n5U*SS2S4   n6U*SS2S4   n7U*SS2S4   n8U*SS2S4   n9U*SS2S4   n:U*SS2S4   n;U*SS2S4   n<U*SS2S4   n=SU-U,-
  -  n>SU/U.-
  -  n?SU1U0-
  -  n@U-S U+-  -
  U,-   nAU/S U+-  -
  U.-   nBU1S U+-  -
  U0-   nCS!U5U4-
  U3-
  U2-   -  nDS!U9U8-
  U7-
  U6-   -  nES!U=U<-
  U;-
  U:-   -  nF[7        UAUBUCUDUEUFU>* U?* U@* 5	      u  nGnHnInJU UJ-  n U R%                  U5      nKUGUK-  nGUHUK-  nHUIUK-  nI[         R                  " U UGU!5      n![         R                  " U UHU"5      n"[         R                  " U UIU#5      n#[         R                  " U U>UG-  U?UH-  -   U@UI-  -   U$5      n$U UGU:  -  nLU UGU* :  -  nMUULR9                  5       -   UMR9                  5       -
  nNU UNS:  -  UNUS	-
  :*  -  n UNR3                  SUS-
  5      nU UHU:  -  nOU UHU* :  -  nPUUOR9                  5       -   UPR9                  5       -
  nQU UQS:  -  UQU
S	-
  :*  -  n UQR3                  SU
S-
  5      nU(       d  GM  U WIU:  -  nRU UIU* :  -  nSUURR9                  5       -   USR9                  5       -
  nTU UTS:  -  UTU	S	-
  :*  -  n UTR3                  SU	S-
  5      nGMS     U U!R;                  5       S":*  -  U"R;                  5       S":*  -  U#R;                  5       S":*  -  n UU-  nUUU-  nV[         R                  " U UR%                  U5      U#-   UR%                  U5      5      nW[         R                  " U UR%                  U5      U!-   UR%                  U5      5      nX[         R                  " U UR%                  U5      U"-   UR%                  U5      5      nYUWUUUUVSUUU4'   UXUUUUVSUUU4'   UYUUUUVS	UUU4'   S[         R                  " U U$[         R<                  " U$5      5      -  nZUUUUU4   n[U[UZ-   UUUUVUUU4'   US:  a$  UWUWVUUU4==   UU R%                  U5      -  -  ss'   X4$ )#u
  Iterative subpixel localization of 3D extrema via quadratic interpolation.

Unlike :func:`conv_quad_interp3d`, which pre-computes the Hessian solve for all
voxels reachable from NMS maxima and then follows shifts by table lookup, this
function explicitly re-extracts the :math:`3 \times 3 \times 3` patch at each
NMS maximum and iterates up to ``n_iters`` times. When the estimated subpixel
shift along any spatial or scale axis exceeds ``max_subpixel_shift`` the integer
center is moved one step in that direction and the solve is repeated — matching
the localization loop from the HessAff / SIFT family of detectors.

Args:
    input: response pyramid with shape :math:`(B, C, D, H, W)`.
    n_iters: maximum number of localization iterations per keypoint.
    strict_maxima_bonus: value added to ``y_max`` at NMS-maximum positions so
        that strict maxima are preferred when selecting the top-K keypoints.
    max_subpixel_shift: if the estimated shift along any axis is larger than this
        threshold the integer center is displaced and another iteration is run.
    allow_scale_steps: if ``True`` (default), the iterative shift is also
        applied along the scale (depth) axis; set to ``False`` to keep the
        keypoint on its original scale level.
    precomputed_nms_mask: optional bool tensor of shape
        :math:`(B, C, D, H, W)` — pass the result of
        :func:`~kornia.geometry.subpix.nms3d` to skip the internal NMS call.
    max_candidates: if given, only the top-``max_candidates`` NMS maxima (ranked by
        pre-refinement response) are processed.  The rest keep their grid-coordinate
        values.  This is a **CPU speed-up knob**: for large images the number of 3-D
        NMS maxima can be 10x-100x larger than the desired number of keypoints,
        making the per-candidate gather+solve loop the dominant CPU cost.  Setting
        ``max_candidates = num_features * 5`` (say) dramatically reduces that work
        at the cost of occasionally missing a feature whose response rank would have
        improved after refinement.

Returns:
    A tuple ``(coords_max, y_max)`` where

    * ``coords_max`` has shape :math:`(B, C, 3, D, H, W)` and stores the refined
      coordinates ``[scale, x, y]`` for every position in the input.
      Non-NMS positions keep their original grid coordinates.
    * ``y_max`` has shape :math:`(B, C, D, H, W)` and stores the quadratically
      corrected response values (with the optional strict-maxima bonus added).

Example:
    >>> input = torch.randn(2, 3, 3, 8, 8)
    >>> coords, vals = iterative_quad_interp3d(input, n_iters=5)
    >>> coords.shape
    torch.Size([2, 3, 3, 3, 8, 8])
    >>> vals.shape
    torch.Size([2, 3, 3, 8, 8])

r   r   r   r   r   r
   Nr   r   r   T)kr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r2   r   r   r   r   topkr   r   r   r   r  rd   r"   r  r  r6   r   r   r   r  )\r   r  rx   r  r
  r  max_candidatesr  r  r  r  r  r   r   r   r  inpr  r  nms_flatr  r  r  r  r  	cand_valsrR  r$  r*  rJ  rK  rL  rM  rN  rO  rP  rQ  r)  bc_based_sh_sw_sr,  r-  r.  r/  r0  r1  r2  r3  r4  r5  r6  r7  r8  r9  r:  r;  r<  r=  r>  r?  r@  rA  rB  r   r   r   r   r   r   r   r   r   r   valid_f
move_pos_x
move_neg_xr_  
move_pos_y
move_neg_yrb  
move_pos_s
move_neg_sre  rf  rg  final_sfinal_xfinal_yrh  ri  s\                                                                                               r   iterative_quad_interp3dr    s   v ??5!!@eNOOzzQI%++WXXKKMA!\\FKKEQ1aAEJJ,,quEJJ1aQRSJq!Qw,,quEJJ1aQRSJq!Qw,,quEJJ1aQRSJq!QwKKME1uAQ  
--qQ
'C
%!)C	
B(<(H$eTY[dfjNkqq	qQH #(++h"7FE5%QA !a.&8ue34	**Y.94dddLL(2-	V0Dq0HH9<<X^K__MKKMEKKMEKKMEJJq

6:Ekk!F8Gkk!F8Gkk!F8G[[6?N{{2HslG7^kk!QU#kk!QU#kk!QU#'C"H,sQw6<GGJ]MdMdefMgghQU|QU|QU|QU|QU|QT{QU|1+2,2,2,1+1+2,2,1+1+2,2,D4K D4K D4K S4Z$&S4Z$&S4Z$&g''1G;<g''1G;<g''1G;<1#sCc3QSPSVXUX[]Z]^BF((5/'\'\'\++eR1++eR1++eR1UBGb2g,=R,GXb#556
b$6#667

))JOO,==!$Q7Aq1u%b#556
b$6#667

))JOO,==!$Q7Aq1u%"'9"9:J"(:':":;JJOO--
0AAEUaZ(EQUN;EKK1q5)EI L W[[]c)*gkkms.BCw{{}X[G[\EaKEQJEkk%%7!:EHHUOLGkk%%7!:EHHUOLGkk%%7!:EHHUOLG7>JueQue347>JueQue347>JueQue345;;une>N>N~>^__NVUE501J/9N/JE%ue
+,QeUE5%/04G%((SX/4YY0r   c                  x   ^  \ rS rSrSr     S           SU 4S jjjrS	S jr S
     SS jjrSrU =r	$ )IterativeQuadInterp3di}  zIterative subpixel localization of 3D extrema via quadratic interpolation.

See :func:`~kornia.geometry.subpix.iterative_quad_interp3d` for details.
c                ^   > [         TU ]  5         Xl        X l        X0l        X@l        XPl        g r?   )r@   rA   r  rx   r  r
  r  )rI   r  rx   r  r
  r  rJ   s         r   rA   IterativeQuadInterp3d.__init__  s-     	#6 "4!2,r   c                    U R                   R                   SU R                   SU R                   SU R                   SU R
                   SU R                   S3$ )Nrp  r{   rq  rs  , max_candidates=rT   )rJ   rU   r  rx   r  r
  r  rV   s    r   rW   IterativeQuadInterp3d.__repr__  sp    ~~&&' (||n %##'#;#;"< =""&"9"9!: ;!!%!7!7 8 9"112!5	
r   c           
         [        UU R                  U R                  U R                  U R                  UU R
                  S9$ )Nr  r  )r  r  rx   r  r
  r  rv  s      r   r]   IterativeQuadInterp3d.forward  sB    
 'LL$$##""!5..
 	
r   )r
  r  r  r  rx   )r   rx  ry  TN)r  rz  rx   r#   r  r#   r
  rd   r  Optional[int]re   rf   rg   r?   r{  rl   rs   s   @r   r  r  }  s     %)$'"&(,-- #- "	-
  - &- 
- -
 8<

 5
 
+	
 
r   r  c                     ^  \ rS rSrSrSr       S               S	U 4S jjjrS
S jr S     SS jjrSr	U =r
$ )AdaptiveQuadInterp3di  u  Subpixel localization of 3D scale-space extrema with automatic backend selection.

Wraps :func:`~kornia.geometry.subpix.conv_quad_interp3d` and
:func:`~kornia.geometry.subpix.iterative_quad_interp3d`, choosing the faster
backend based on the input device and the requested ``mode``.

Benchmarks show:

* **GPU** — :func:`conv_quad_interp3d` is 1.5-2x faster due to better
  parallelism on the batched gather+solve.
* **CPU** — :func:`iterative_quad_interp3d` is faster for large images because
  it processes only the NMS maxima directly without any dilation/dedup overhead.

Args:
    mode: backend selection strategy.

        * ``"patch"`` — always use :func:`iterative_quad_interp3d`.
        * ``"conv"``  — always use :func:`conv_quad_interp3d`.
        * ``"auto"``  — use ``"conv"`` when the input is on a CUDA device,
          ``"patch"`` otherwise.

    n_iters: maximum localization iterations per keypoint.
    strict_maxima_bonus: score bonus added at NMS-maximum positions.
    max_subpixel_shift: integer-centre move threshold.
    dilation_radius: L\ :math:`\infty` precompute radius for ``"conv"`` mode
        (ignored in ``"patch"`` mode).
    max_candidates: if set, only the top-``max_candidates`` NMS maxima by
        pre-refinement response are processed in ``"patch"`` mode.  Has no effect
        in ``"conv"`` mode.  Useful on CPU when the number of 3-D NMS maxima greatly
        exceeds the desired number of keypoints (see :func:`iterative_quad_interp3d`).

Example:
    >>> inp = torch.randn(1, 1, 3, 64, 64)
    >>> subpix = AdaptiveQuadInterp3d(mode="auto")
    >>> coords, vals = subpix(inp)
    >>> coords.shape
    torch.Size([1, 1, 3, 3, 64, 64])
    >>> vals.shape
    torch.Size([1, 1, 3, 64, 64])

)r,  convautoc                   > [         TU ]  5         XR                  ;  a  [        SU R                   SU S35      eXl        X l        X0l        X@l        XPl        X`l	        Xpl
        g )Nzmode must be one of z, got '')r@   rA   MODESr   moder  rx   r  r	  r
  r  )	rI   r  r  rx   r  r	  r
  r  rJ   s	           r   rA   AdaptiveQuadInterp3d.__init__  sa     	zz!3DJJ<wtfANOO	#6 "4.!2,r   c                    U R                   R                   SU R                   SU R                   SU R                   SU R
                   SU R                   SU R                   SU R                   S3$ )	Nz(mode='z', n_iters=r{   rq  rr  rs  r  rT   )	rJ   rU   r  r  rx   r  r	  r
  r  rV   s    r   rW   AdaptiveQuadInterp3d.__repr__  s    ~~&&' (YYK  ||n %##'#;#;"< =""&"9"9!: ;#334 5!!%!7!7 8 9"112!5		
r   c           
        U R                   S:H  =(       d"    U R                   S:H  =(       a    UR                  nU(       aC  [        UU R                  U R                  U R
                  UU R                  U R                  5      $ [        UU R                  U R                  U R
                  U R                  UU R                  S9$ )Nr  r  r  )
r  is_cudarj  r  rx   r  r	  r
  r  r  )rI   r\   r  use_convs       r   r]   AdaptiveQuadInterp3d.forward  s    
 99&M499+>+L199%((''$$$&&  'LL$$##""!5..
 	
r   )r
  r	  r  r  r  r  rx   )r  r   rx  ry  r
   TN)r  rh   r  rz  rx   r#   r  r#   r	  rz  r
  rd   r  r  re   rf   rg   r?   r{  )rU   rm   rn   ro   rp   r  rA   rW   r]   rq   rr   rs   s   @r   r  r    s    (T &E %)$' "&(,-- - #	-
 "- -  - &- 
- -*

 8<

 5
 
+	
 
r   r  r?   )r   rz  r   rz  r   Optional[torch.device]re   rj   )
r+   rz  r   rz  r   rz  r   r  re   rj   r_   )r   rj   rB   rb   rC   rb   rD   rb   rE   rc   rF   rd   rG   r#   rH   rd   re   rk   r   )r   rj   rB   r   rC   r   rD   r   rE   rc   rF   rd   rG   r#   rH   rd   rx   r#   re   rk   r   )r   rj   rE   r   rF   rd   re   rj   )gHz>)r   rj   r   rj   r   rj   r   rj   r   rj   r   rj   r   rj   r   rj   r   rj   rG   r#   re   z=tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor])r   rx  ry  Nr
   T)r   rj   r  rz  rx   r#   r  r#   r  r   r	  rz  r
  rd   re   r|  )r   rx  ry  TNN)r   rj   r  rz  rx   r#   r  r#   r
  rd   r  r   r  r  re   r|  )*
__future__r   typingr   r   torch.nn.functionalr   
functionalr   kornia.geometry.conversionsr   r   kornia.geometry.gridr   r	   dsntr   r   nmsr   r   r   r   r   r   r   r)   r/   r:   Moduler<   ru   rZ   r~   r   r   r   rj  rl  r  r  r   r   r   <module>r     sz  $ #      b C :  LL^
**	 LL^
**	 LL^
**	(B%P20
ryy 0
f4
ryy 4
r $*$%(+#'oo o o 	o
 &o !o 
o o 6oh )2#,$-(+#(!$~%~%%~% !~% "	~%
 &~% !~% 
~% ~% ~% 6~%D ei&<]a>[")) [D -	-	- 
- 
	-
 
- 
- 	- 	- 	- 
- C-d !% #37"AAA A 	A
 1A A A 'AH3
ryy 3
p !% #"37$(TTT T 	T
 T 1T "T 'Tn,
BII ,
^f
299 f
r   