+
    åûj½P ã                  ó4  € R t ^ RIHt ^ RIt^ RIt^ RIHt ^ RIt^ RIH	u H
t ^ RIH	t	 ^ RIHtHt ^ RIHtHt ^RIHtHtHt ^RIHt ]P0                  ! . R4O]P2                  R	7      t]P0                  ! . R5O]P2                  R	7      t]P0                  ! . R6O]P2                  R	7      tR
 R ltR7R R lltR7R R lltR7R R llt R7R R llt! ! R R]	PD                  4      t# ! R R]	PD                  4      t$R R lt%R8R R llt&R9R R llt'R:R R llt( ! R  R!]	PD                  4      t)R" R# lt*R;R$ R% llt+R& R' lt,R;R( R) llt-R<R* R+ llt. ! R, R-]	PD                  4      t/R=R. R/ llt0 ! R0 R1]	PD                  4      t1 ! R2 R3]	PD                  4      t2R# )>zgSoft-argmax over whole heatmaps and sliding windows, and quadratic refinement of 3D scale-space maxima.)ÚannotationsN)ÚOptional)Únn)Únormalize_pixel_coordinatesÚnormalize_pixel_coordinates3d)Úcreate_meshgridÚcreate_meshgrid3d)Ú_check_positive_temperatureÚspatial_expectation2dÚspatial_softmax2d)Únms3d)Údtypec               ó   € V ^8„  d   QhRR/# )é   ÚreturnÚNone© )Úformats   "ÚfC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\geometry\subpix\spatial_soft_argmax.pyÚ__annotate__r   6   s   € ÷ ñ  4ñ ó    c                 ó@   € \         P                  ! R \        ^R7       R# )zö`strict_maxima_bonus` is deprecated since kornia 0.9.0 and is ignored: no bonus is added to the returned values. The argument will be removed in a future release. To keep only strict maxima, select them with a `kornia.geometry.subpix.nms3d` mask.)Ú
stacklevelN)ÚwarningsÚwarnÚDeprecationWarningr   r   r   Ú_warn_strict_maxima_bonusr   6   s   € ä‡M‚Mð	/ô 	Ø÷r   c               ó(   € V ^8„  d   QhRRRRRRRR/# ©r   ÚhÚintÚwÚdeviceúOptional[torch.device]r   útorch.Tensorr   )r   s   "r   r   r   A   s*   € ÷ -ñ - ð -¨ð -Ð6Lð -ÐXdñ -r   c                ó  € Vf   \         P                  ! R4      p\        WRVR7      pV\         P                  ! V^,
          ^,          V ^,
          ^,          .W#P                  R7      ,
          pVP                  ^^ ^^4      # )zÊGenerate 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©r"   ©r"   r   )Útorchr"   r   Útensorr   Úpermute)r   r!   r"   Úwindow_grid2ds   &&& r   Ú_get_window_grid_kernel2dr-   A   sm   € ð ‚~Ü—’˜eÓ$ˆä# A¨%¸Ô?€MØ!¤E§L¢L°1°qµ5¸Aµ+ÀÀAÅÈ½{Ð1KÐTZ×buÑbuÔ$vÕv€MØ× Ñ   A q¨!Ó,Ð,r   c               ó(   € V ^8„  d   QhRRRRRRRR/# r   r   )r   s   "r   r   r   U   s*   € ÷ ñ ˜Cð  Cð Ð1Gð ÐS_ñ r   c                óê  € Vf   \         P                  ! R4      p\         P                  ! ^^WVR7      pV ^,          ^ 8w  d   V ^,          pV ^,          ^,           pM V ^,          ^,
          pV ^,          ^,           pV^,          ^ 8w  d   V^,          pV^,          ^,           pM V^,          ^,
          pV^,          ^,           pR\        WT,
          Wv,
          ,          4      ,          VRRWE1Wg13&   V# )zâGenerate 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"   ÚzerosÚfloat)r   r!   r"   Úcenter_kernelÚh_i1Úh_i2Úw_i1Úw_i2s   &&&     r   Ú_get_center_kernel2dr;   U   sÕ   € ð ‚~Ü—’˜eÓ$ˆÜ—K’K  1 a°6Ô:€Mð 	ˆ1…u�„zØ�A�vˆØ�Q•˜!�|‰à�Q•˜!�|ˆØ�Q•˜!�|ˆØˆ1…u�„zØ�A�vˆØ�Q•˜!�|‰à�Q•˜!�|ˆØ�Q•˜!�|ˆØ:=ÄÀtÅ{ÐW[ÕWbÕFcÓ@dÕ:d€M�&˜& $ )¨T¨YÐ6Ñ7ØÐr   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# ©	r   Údr    r   r!   r"   r#   r   r$   r   )r   s   "r   r   r   v   s1   € ÷ %ñ %˜Cð % Cð %¨Cð %Ð9Oð %Ð[gñ %r   c           	     óœ  € Vf   \         P                  ! R4       \         P                  ! ^^WW#R7      pV^,          ^ 8w  d   V^,          pV^,          ^,           pM V^,          ^,
          pV^,          ^,           pV^,          ^ 8w  d   V^,          pV^,          ^,           pM V^,          ^,
          pV^,          ^,           pV ^,          ^ 8w  d   V ^,          p	V ^,          ^,           p
M V ^,          ^,
          p	V ^,          ^,           p
\        We,
          W‡,
          ,          W©,
          ,          4      pRV,          VRRWš1WV1Wx13&   V# )zùGenerate 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'   r0   )r1   r2   r   r3   )r>   r   r!   r"   r6   r7   r8   r9   r:   Úd_i1Úd_i2Ú
center_nums   &&&&        r   Ú_get_center_kernel3drC   v   s  € ð ‚~Ü�Š�UÔÜ—K’K  1 a¨AÔ=€Màˆ1…u�„zØ�A�vˆØ�Q•˜!�|‰à�Q•˜!�|ˆØ�Q•˜!�|ˆØˆ1…u�„zØ�A�vˆØ�Q•˜!�|‰à�Q•˜!�|ˆØ�Q•˜!�|ˆØˆ1…u�„zØ�A�vˆØ�Q•˜!�|‰à�Q•˜!�|ˆØ�Q•˜!�|ˆÜ˜�¨­Õ4¸½ÕDÓE€JØKNÐQ[ÕK[€M�)˜Y¨¨	°4°9¸d¸iÐGÑHØÐr   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# r=   r   )r   s   "r   r   r   ž   s1   € ÷ 3ñ 3 ð 3¨ð 3°ð 3Ð>Tð 3Ð`lñ 3r   c           	     óL  € Vf   \         P                  ! R4      p\        WRVR7      pV\         P                  ! V^,
          ^,          V^,
          ^,          .W4P                  R7      ,
          p\         P
                  ! WVP                  R7      V ^,
          ^,          ,
          P                  V ^^^4      p\         P                  ! VP                  ^W^4      P                  4       VP                  V ^^^4      .^4      pVP                  ^^ ^^4      P                  ^4      # )zÙGenerate 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&   Fr'   r(   )r)   r"   r   r*   r   ÚarangeÚviewÚcatÚrepeatÚ
contiguousr+   Ú	unsqueeze)r>   r   r!   r"   Úgrid2dÚzÚgrid3ds   &&&&   r   Ú_get_window_grid_kernel3drO   ž   sç   € ð ‚~Ü—’˜eÓ$ˆä˜Q 5°Ô8€FØ”e—l’l Q¨¥U¨a¥K°!°aµ%¸1µÐ#=Àf×T`ÑT`ÔaÕa€FÜ	�Š�a¨f¯l©lÔ	;¸qÀ1½uÈ½kÕ	I×OÑOÐPQÐSTÐVWÐYZÓ[€AÜ�YŠY˜Ÿ™  A¨!Ó,×7Ñ7Ó9¸6¿=¹=ÈÈAÈqÐRSÓ;TÐUÐWXÓY€FØ�>‰>˜!˜Q  1Ó%×/Ñ/°Ó2Ð2r   c                  óN   a € ] tR t^µtRtR	R V 3R llltR R ltR R ltRtV ;t	# )
ÚConvSoftArgmax2da  Compute a soft-argmax (x, y) per window; the module form of conv_soft_argmax2d.

``op = ConvSoftArgmax2d(kernel_size, stride, padding)`` stores the arguments of :func:`conv_soft_argmax2d`, and
``coords = op(heatmap)`` returns what that function returns for them: the ``(B, C, 2, H_out, W_out)`` window
coordinates in ``(x, y)`` order, normalized by default, and with ``output_value=True`` the pair
``(coords, values)``.

Convention:
    - See the convention block of :func:`~kornia.geometry.subpix.conv_soft_argmax2d`.

See Also:
    - :func:`conv_soft_argmax2d`: the function form.
    - :class:`ConvSoftArgmax3d`: the module for ``(B, C, D, H, W)`` volumes, in voxels and with values by
      default.
    - :class:`SpatialSoftArgmax2d`: one soft-argmax per channel over the whole map.

c               ó8   € V ^8„  d   QhRRRRRRRRRRR	R
RRRR/# )r   Úkernel_sizeútuple[int, int]ÚstrideÚpaddingÚtemperatureútorch.Tensor | floatÚnormalized_coordinatesÚboolÚepsr5   Úoutput_valuer   r   r   )r   s   "r   r   ÚConvSoftArgmax2d.__annotate__È   sZ   € ÷ )ñ )à$ð)ð  ð)ð !ð	)ð
 *ð)ð !%ð)ð ð)ð ð)ð 
ñ)r   c                	óx   <€ \         SV `  4        Wn        W n        W0n        W@n        WPn        W`n        Wpn        R # ©N)	ÚsuperÚ__init__rS   rU   rV   rW   rY   r[   r\   )	ÚselfrS   rU   rV   rW   rY   r[   r\   Ú	__class__s	   &&&&&&&&€r   ra   ÚConvSoftArgmax2d.__init__È   s7   ø€ ô 	‰ÑÔØ&ÔØŒØŒØ&ÔØ&<Ô#ØŒØ(Ör   c               ó   € V ^8„  d   QhRR/# ©r   r   Ústrr   )r   s   "r   r   r]   Û   ó   € ÷ 

ñ 

˜#ñ 

r   c                	óê   € V P                   P                   R V P                   RV P                   RV P                   RV P
                   RV P                   RV P                   RV P                   R2# ©z(kernel_size=z	, stride=z
, padding=z, temperature=ú, normalized_coordinates=z, eps=z, output_value=Ú)©	rc   Ú__name__rS   rU   rV   rW   rY   r[   r\   ©rb   s   &r   Ú__repr__ÚConvSoftArgmax2d.__repr__Û   óŠ   € à�~‰~×&Ñ&Ð'Ø˜D×,Ñ,Ð-ð .Ø—k‘k�]ð #Ø—|‘|�nð %Ø×+Ñ+Ð,ð -&Ø&*×&AÑ&AÐ%Bð CØ—8‘8�*ð Ø ×-Ñ-Ð.¨að1ð		
r   c               ó    € V ^8„  d   QhRRRR/# ©r   Úxr$   r   ú0torch.Tensor | tuple[torch.Tensor, torch.Tensor]r   )r   s   "r   r   r]   ç   s   € ÷ 
ñ 
˜ð 
Ð*Zñ 
r   c           
     ó²   € \        VV P                  V P                  V P                  V P                  V P
                  V P                  V P                  4      # )a†  Estimate local 2D coordinates from heatmap windows.

The operation applies soft-argmax inside sliding windows. Instead of
choosing the hard maximum location, it computes an expectation over
window coordinates, which gives differentiable subpixel coordinates.

Args:
    x: Heatmap tensor with shape ``(B, C, H, W)``, where
        :math:`B` is batch size, :math:`C` is the number of heatmap
        channels, :math:`H` is height, and :math:`W` is width.

Returns:
    Coordinates from :func:`conv_soft_argmax2d`. If
    ``self.output_value`` is ``True``, returns ``(coords, values)``,
    where ``values`` are the corresponding window responses.
)Úconv_soft_argmax2drS   rU   rV   rW   rY   r[   r\   ©rb   ru   s   &&r   ÚforwardÚConvSoftArgmax2d.forwardç   sM   € ô" "ØØ×ÑØ�K‰KØ�L‰LØ×ÑØ×'Ñ'Ø�H‰HØ×Ñó	
ð 		
r   ©r[   rS   rY   r\   rV   rU   rW   ©)é   r~   ©r2   r2   r   r0   Tç:Œ0âŽyE>F©
rn   Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__ra   rp   rz   Ú__static_attributes__Ú__classcell__©rc   s   @r   rQ   rQ   µ   s!   ø† ñ÷$)ò )õ&

÷
ó 
r   rQ   c                  óN   a € ] tR tRtRtR
R V 3R llltR R ltR R ltR	tV ;t	# )ÚConvSoftArgmax3di  aX  Compute a soft-argmax (d, x, y) per window; the module form of conv_soft_argmax3d.

``op = ConvSoftArgmax3d(kernel_size, stride, padding)`` stores the arguments of :func:`conv_soft_argmax3d`, and
``coords, values = op(volume)`` returns what that function returns for them: the ``(B, C, 3, D_out, H_out, W_out)``
window coordinates in ``(d, x, y)`` order, in voxels by default, and the ``(B, C, D_out, H_out, W_out)``
softmax-pooled values; with ``output_value=False``, the coordinates alone. Passing ``strict_maxima_bonus`` emits a
:class:`DeprecationWarning` and has no effect.

Convention:
    - See the convention block of :func:`~kornia.geometry.subpix.conv_soft_argmax3d`.

See Also:
    - :func:`conv_soft_argmax3d`: the function form.
    - :class:`ConvSoftArgmax2d`: the module for ``(B, C, H, W)`` maps, normalized and without values by default.

c               ó<   € V ^8„  d   QhRRRRRRRRRR	R
RRR	RRRR/	# )r   rS   útuple[int, int, int]rU   úint | tuple[int, int, int]rV   rW   rX   rY   rZ   r[   r5   r\   Ústrict_maxima_bonusúOptional[float]r   r   r   )r   s   "r   r   ÚConvSoftArgmax3d.__annotate__  sd   € ÷ )ñ )à)ð)ð +ð)ð &ð	)ð
 *ð)ð !%ð)ð ð)ð ð)ð -ð)ð 
ñ)r   c	                	ó”   <€ \         S	V `  4        Ve   \        4        Wn        W n        W0n        W@n        WPn        W`n        Wpn	        R # r_   )
r`   ra   r   rS   rU   rV   rW   rY   r[   r\   )
rb   rS   rU   rV   rW   rY   r[   r\   rŽ   rc   s
   &&&&&&&&&€r   ra   ÚConvSoftArgmax3d.__init__  sC   ø€ ô 	‰ÑÔØÒ*Ü%Ô'Ø&ÔØŒØŒØ&ÔØ&<Ô#ØŒØ(Ör   c               ó   € V ^8„  d   QhRR/# rf   r   )r   s   "r   r   r�   ,  rh   r   c                	óê   € V P                   P                   R V P                   RV P                   RV P                   RV P
                   RV P                   RV P                   RV P                   R2# rj   rm   ro   s   &r   rp   ÚConvSoftArgmax3d.__repr__,  rr   r   c               ó    € V ^8„  d   QhRRRR/# rt   r   )r   s   "r   r   r�   8  s   € ÷ 
ñ 
˜ð 
Ð*Zñ 
r   c           
     ó²   € \        VV P                  V P                  V P                  V P                  V P
                  V P                  V P                  4      # )aÈ  Estimate local 3D coordinates from response-volume windows.

Args:
    x: Response tensor with shape ``(B, C, D, H, W)``, where
        :math:`B` is batch size, :math:`C` is channel count,
        :math:`D` is depth or scale level, :math:`H` is height, and
        :math:`W` is width.

Returns:
    Coordinates from :func:`conv_soft_argmax3d`. If
    ``self.output_value`` is ``True``, returns ``(coords, values)``;
    otherwise returns only coordinates.
)Úconv_soft_argmax3drS   rU   rV   rW   rY   r[   r\   ry   s   &&r   rz   ÚConvSoftArgmax3d.forward8  sM   € ô "ØØ×ÑØ�K‰KØ�L‰LØ×ÑØ×'Ñ'Ø�H‰HØ×Ñó	
ð 		
r   r|   ©©r~   r~   r~   ©r2   r2   r2   rœ   r0   Fr€   TNr�   rˆ   s   @r   rŠ   rŠ     s!   ø† ñ÷")ò )õ,

÷
ó 
r   rŠ   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   Úpaddedr$   rS   rŒ   rU   r   r   )r   s   "r   r   r   R  s1   € ÷ bñ b�lð bÐ1Eð bÐOcð bÐhtñ br   c           
     ó  € V P                   w  r4rVpVw  r‰p
Vw  r¼p\        P                  ! V P                  W5,          ^Wg4      Wš3WÍ3R7      pVP                   R,          pVP	                  W5Wš,          V4      p\
        P                  P                  4       '       d“   WµV,
          V,          ,          p\
        P                  ! \        V4       Uu. uF  pVRVVV,           ^,           V13,          NK!  	  up^R7      pVP                  W>P                   ^,          W‰,          V
,          V4      # VP                  ^W‹4      pVP                  ^ ^^^^4      P                  W>P                   ^,          W‰,          V
,          V4      # u upi )zýUnfold an already padded ``(N, 1, D, H, W)`` volume into ``(N, D_out, kz * ky * kx, H_out * W_out)`` windows.

Each depth slice is unfolded like an image, then the slices are unfolded along depth, so the window values are in
(depth, row, column) order.
©rU   ºNNN©Údiméÿÿÿÿ)ÚshapeÚFÚunfoldÚreshaperG   r)   ÚonnxÚis_in_onnx_exportÚstackÚranger+   )rž   rS   rU   ÚnÚ_Úd_pÚh_pÚw_pÚkzÚkyÚkxÚszÚsyÚsxÚcolumnsÚnum_windowsÚlastÚis   &&&               r   Ú	_unfold3dr¼   R  sC  € ð !Ÿ,™,Ñ€Aˆ#�CØ�J€BˆBØ�J€BˆBÜ�hŠh�v—~‘~ a¥g¨q°#Ó;¸b¸XÈrÈhÔW€GØ—-‘- Õ#€KØ�l‰l˜1 2¥7¨KÓ8€GÜ‡z�z×#Ñ#×%Ò%ð ˜B•h 2Õ%Õ&ˆÜ—+’+Ì%ÐPRÌ)ÓTÉ)ÀQ˜w q¨!¨a°$­h¸­l¸RÐ*?Ð'?×@Ð@É)ÑTÐZ[Ô\ˆØ�‰˜q§-¡-°Õ"2°BµG¸bµLÀ+ÓNÐNØ�n‰n˜Q Ó'€GØ�?‰?˜1˜a  A qÓ)×1Ñ1°!·]±]À1Õ5EÀrÅwÐQSÅ|ÐU`ÓaÐaùò Us   Ã%Fc               ó<   € V ^8„  d   QhRRRRRRRRRRR	R
RRRR
RR/	# )r   Úinputr$   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r5   r\   r   rv   r   )r   s   "r   r   r   h  sm   € ÷ T%ñ T%ØðT%à ðT%ð ðT%ð ð	T%ð
 &ðT%ð !ðT%ð 
ðT%ð ðT%ð 6ñT%r   c           	     óŒ  € \         P                  ! V 4      '       g   \        R\        V 4       24      h\	        V P
                  4      ^8X  g   \        RV P
                   24      h\        V4       V P
                  w  r‰r«Vw  rÍ\        V\        4      '       d   W"3MTw  rï\        V\        4      '       d   W33MTw  ppV P                  pV P                  pV P                  W‰,          ^W«4      p \        WÍV4      P                  V4      p\        WÍV4      P                  V4      p^ ^V,          u;8:  d   V8:  d   M M^ ^V,          u;8:  d   V8:  g   M \        RV RV 24      hW‰,          pV
^V,          ,           V,
          V,          ^,           pV^V,          ,           V,
          V,          ^,           p\         P"                  ! \         P$                  ! W,          VVVV.\'        R4      R7      WR7      p\         P(                  ! V^R7      p\+        V
^V,          ,           V^V,          ,           R	V4      pV\         P,                  ! VV.VVP                  R
7      ,
          pVP                  V4      P/                  ^ ^^^4      p\         P0                  ! VVVR7      pVP                  ^WÍ,          4      pVV,          P3                  V^VV4      VP5                  V^VV4      ,           pV'       d3   \7        VP/                  ^ ^^^4      W«4      pVP/                  ^ ^^^4      pVP3                  W‰^VP9                  ^4      VP9                  ^4      4      pV'       g   V# \         P"                  ! \         P$                  ! V VVVV.4      WR7      pVV,          P;                  ^4      P3                  W‰VV4      p VV 3# )a  Compute a soft-argmax (x, y) in every sliding window of a (B, C, H, W) heatmap.

``coords = conv_soft_argmax2d(heatmap)`` takes a ``(B, C, H, W)`` heatmap and returns, for every ``kernel_size``
window at every ``stride``, the mean position of its pixels under the softmax of the window's values divided by
``temperature``: ``(B, C, 2, H_out, W_out)`` with ``(x, y)`` along dimension 2, normalized to :math:`[-1, 1]` by
default or in pixels with ``normalized_coordinates=False``. With ``output_value=True`` it also returns the
softmax-weighted mean value of each window, ``(B, C, H_out, W_out)``. The default ``(3, 3)`` window with stride 1
and padding 1 gives ``H_out, W_out = H, W``. Each window locates its own peak; for one location per channel over
the whole map, use :func:`spatial_soft_argmax2d`, and for ``(B, C, D, H, W)`` volumes, :func:`conv_soft_argmax3d`.

.. math::
    xy(X) = \frac{\sum_{p \in X} (x_p, y_p) \exp(v_p / T)}{\sum_{p \in X} \exp(v_p / T)}

.. math::
    val(X) = \frac{\sum_{p \in X} v_p \exp(v_p / T)}{\sum_{p \in X} \exp(v_p / T)}

where :math:`X` is a window, :math:`(x_p, y_p)` the column and row of its pixel :math:`p`, :math:`v_p` the
heatmap value there and :math:`T` the temperature.

Convention:
    - Coordinates follow :ref:`Coordinates and sizes <coordinate-conventions>`. This function defaults to
      normalized, corner-aligned coordinates.
      :func:`conv_soft_argmax3d` defaults to pixel coordinates and ``output_value=True`` instead.
    - ``padding`` adds positions of zero weight, as if the input were padded with ``-inf``: a window that
      overhangs the border averages over its in-image pixels only.
    - Each window is the softmax of its own values: the exponent is shifted by the window's maximum, so a
      window's coordinates and value do not depend on the rest of the map, in float16 either. ``eps`` is
      accepted and has no effect (`#5020 <https://github.com/kornia/kornia/issues/5020>`_).

Args:
    input: the given heatmap with shape ``(B, C, H, W)``.
    kernel_size: the size ``(ky, kx)`` of the window.
    stride: the stride of the window.
    padding: the padding added to each side of the input, at most half of ``kernel_size`` on every axis.
    temperature: softmax temperature: the input is divided by it; smaller is sharper. Must be positive.
      A tensor temperature is not checked under ``torch.compile`` or export.
    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: accepted for backward compatibility and ignored; every window's softmax denominator is at least 1.
    output_value: whether to also return the softmax-pooled value of each window.

Returns:
    the coordinates of each window, ``(B, C, 2, H_out, W_out)`` with ``(x, y)`` along dimension 2, and with
    ``output_value=True`` also the softmax-pooled heatmap values, ``(B, C, H_out, W_out)``,

    where

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

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

Raises:
    TypeError: if ``input`` is not a tensor.
    ValueError: if ``input`` is not 4D, if ``padding`` is negative or more than half of ``kernel_size`` on an
      axis, or if ``temperature`` is not positive.

See Also:
    - :func:`conv_soft_argmax3d`: the same per-window soft-argmax over a ``(B, C, D, H, W)`` volume, returning
      ``(d, x, y)``, in voxels and with values by default.
    - :func:`spatial_soft_argmax2d`: one soft-argmax per channel, over the whole map.
    - :class:`ConvSoftArgmax2d`: the module form.
    - :func:`nms2d`: the strict local maxima of a window, at integer positions and without a softmax.

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: úBpadding must be non-negative and at most half of kernel_size. Got ú for kernel_size ú-inf©Úvaluer    r¢   Fr(   )r)   Ú	is_tensorÚ	TypeErrorÚtypeÚlenr¥   Ú
ValueErrorr	   Ú
isinstancer    r"   r   r¨   r;   Útor-   r¦   r§   Úpadr5   Úsoftmaxr   r*   r+   Úconv2drG   Úexpandr   ÚsizeÚsum)!r¾   rS   rU   rV   rW   rY   r[   r\   ÚbÚcr   r!   r³   r´   r¶   r·   ÚpyÚpxr"   r   r6   Úwindow_kernelr­   Úh_outÚw_outÚlogitsÚweightsÚgrid_globalÚgrid_global_pooledÚoffsetsÚ
coords_maxÚwindowsÚx_softmaxpools!   &&&&&&&&                         r   rx   rx   h  s5  € ôd �?Š?˜5×!Ò!ÜÐ@ÄÀeÃÀÐNÓOÐOäˆu�{‰{Ó˜qÔ ÜÐHÈÏÉÈÐVÓWÐWä Ô,à—‘�J€Aˆ!Ø�F€BÜ!+¨F´C×!8Ò!8ˆfÑ¸f�F€BÜ#-¨g´s×#;Ò#;ˆgÑÀ�F€BˆØ Ÿ<™<€FØŸ™€EØ�M‰M˜!�%  AÓ)€Eä"6°r¸vÓ"F×"IÑ"IÈ%Ó"P€MÜ";¸BÀFÓ"K×"NÑ"NÈuÓ"U€Mà��R•Ö˜2× ! q¨2¥vÖ"3°Ö"3ÜØPÐQXÐPYÐYjÐkvÐjwÐxó
ð 	
ð 	
�€AØ��R•�Z˜"�_ Õ# aÕ'€EØ��R•�Z˜"�_ Õ# aÕ'€EÜ�XŠX”a—e’e˜EÕ/°"°b¸"¸bÐ1AÌÈvËÔWÐYdÔt€FÜ�mŠm˜F¨Ô*€Gô !0°°A¸µFµ
¸AÀÀBÅ½JÈÈvÓ V€KØ¤§¢¨b°"¨X¸fÈK×L]ÑL]Ô ^Õ^€KØ—.‘. Ó'×/Ñ/°°1°a¸Ó;€KäŸš +¨}ÀVÔLÐð ×#Ñ# A r¥wÓ/€GØ˜GÕ#×)Ñ)¨!¨Q°°uÓ=Ð@R×@YÑ@YÐZ[Ð]^Ð`eÐglÓ@mÕm€J÷ Ü0°×1CÑ1CÀAÀqÈ!ÈQÓ1OÐQRÓVˆ
Ø×'Ñ'¨¨1¨a°Ó3ˆ
ð —‘  q¨*¯/©/¸!Ó*<¸j¿o¹oÈaÓ>PÓQ€JçØÐô �hŠh”q—u’u˜U R¨¨R°Ð$4Ó5°{ÔR€GØ˜wÕ&×+Ñ+¨AÓ.×3Ñ3°A¸%ÀÓG€MØ�}Ð$Ð$r   c               ó@   € V ^8„  d   QhRRRRRRRRRR	R
RRRRRRRRR/
# )r   r¾   r$   rS   rŒ   rU   r�   rV   rW   rX   rY   rZ   r[   r5   r\   rŽ   r�   r   rv   r   )r   s   "r   r   r   ÿ  sx   € ÷ V%ñ V%ØðV%à%ðV%ð 'ðV%ð "ð	V%ð
 &ðV%ð !ðV%ð 
ðV%ð ðV%ð )ðV%ð 6ñV%r   c	           
     ó   € Ve   \        4        \        P                  ! V 4      '       g   \        R\	        V 4       24      h\        V P                  4      ^8X  g   \        RV P                   24      h\        V4       V P                  w  ršr¼pVw  rïp\        V\        4      '       d   W"V3MTw  ppp\        V\        4      '       d   W3V3MTw  pppV P                  pV P                  pV P                  Wš,          ^W¼V4      p \        WïVV4      P                  V4      p\!        WïVV4      P                  V4      p^ ^V,          u;8:  d   V8:  d5   M M1^ ^V,          u;8:  d   V8:  d   M M^ ^V,          u;8:  d   V8:  g   M \        RV RV 24      hWš,          pV^V,          ,           V,
          V,          ^,           pV^V,          ,           V,
          V,          ^,           pV^V,          ,           V,
          V,          ^,           pVVVVVV.p\#        \$        P&                  ! W,          V\)        R4      R7      VVVV34      p \        P*                  ! V ^R7      p!\-        V^V,          ,           V^V,          ,           V^V,          ,           RVR	7      p"V"\        P.                  ! VVV.VV"P                  R
7      ,
          p"V"P                  V4      P1                  ^ ^^^^4      p"\$        P2                  ! V"VVVV3R7      p#VP                  ^Wï,          V,          4      p$V$V!,          P5                  VV^VV4      P7                  ^^4      p%V%V#P9                  V^VVV4      ,           p%V'       d6   \;        V%P1                  ^ ^^^^4      W¼V4      p%V%P1                  ^ ^^^^4      p%V%P5                  Wš^V%P=                  ^4      V%P=                  ^4      V%P=                  ^4      4      p%V'       g   V%# \#        \$        P&                  ! V V4      VVVV34      p&V!V&,          P?                  ^4      P5                  WšVVV4      p'V%V'3# )a@  Compute a soft-argmax (d, x, y) in every sliding window of a (B, C, D, H, W) volume.

``coords, values = conv_soft_argmax3d(volume)`` takes a ``(B, C, D, H, W)`` volume and returns, for every
``kernel_size`` window at every ``stride``, the mean position of its voxels under the softmax of the window's
values divided by ``temperature``, ``(B, C, 3, D_out, H_out, W_out)`` with ``(d, x, y)`` along dimension 2, and
the softmax-weighted mean value of each window, ``(B, C, D_out, H_out, W_out)``. Unlike
:func:`conv_soft_argmax2d`, it defaults to voxel coordinates and to returning the values; pass
``normalized_coordinates=True`` for :math:`[-1, 1]` coordinates and ``output_value=False`` for the coordinates
alone. To refine only the strict maxima of a scale-space volume by a quadratic fit, use
:func:`conv_quad_interp3d` instead.

.. math::
    dxy(X) = \frac{\sum_{p \in X} (d_p, x_p, y_p) \exp(v_p / T)}{\sum_{p \in X} \exp(v_p / T)}

.. math::
    val(X) = \frac{\sum_{p \in X} v_p \exp(v_p / T)}{\sum_{p \in X} \exp(v_p / T)}

where :math:`X` is a window, :math:`(d_p, x_p, y_p)` the depth, column and row of its voxel :math:`p`,
:math:`v_p` the heatmap value there and :math:`T` the temperature.

Convention:
    - See the convention block of :func:`conv_soft_argmax2d`. Coordinates follow
      :ref:`Coordinates and sizes <coordinate-conventions>`; this function defaults to pixel coordinates.

Args:
    input: the given heatmap with shape ``(B, C, D, H, W)``.
    kernel_size: the size ``(kd, ky, kx)`` of the window.
    stride: stride of the window, an ``int`` for every axis or a tuple ``(sd, sy, sx)``.
    padding: the padding added to each side of the input, at most half of ``kernel_size`` on every axis.
    temperature: softmax temperature: the input is divided by it; smaller is sharper. Must be positive.
      A tensor temperature is not checked under ``torch.compile`` or export.
    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: accepted for backward compatibility and ignored; every window's softmax denominator is at least 1.
    output_value: whether to also return the softmax-pooled value of each window.
    strict_maxima_bonus: deprecated since kornia 0.9.0 and ignored; passing it emits a
      :class:`DeprecationWarning`. Select strict maxima with :func:`~kornia.geometry.subpix.nms3d` instead.

Returns:
    the coordinates of each window, ``(B, C, 3, D_out, H_out, W_out)`` with ``(d, x, y)`` along dimension 2, and
    with ``output_value=True`` (the default) also the softmax-pooled values, ``(B, C, D_out, H_out, W_out)``,

    where

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

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

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

Raises:
    TypeError: if ``input`` is not a tensor.
    ValueError: if ``input`` is not 5D, if ``padding`` is negative or more than half of ``kernel_size`` on an
      axis, or if ``temperature`` is not positive.

See Also:
    - :func:`conv_soft_argmax2d`: the same per-window soft-argmax over a ``(B, C, H, W)`` map, returning
      ``(x, y)``, normalized and without values by default.
    - :func:`conv_quad_interp3d`: refines only the strict maxima of a volume, by a quadratic fit.
    - :class:`ConvSoftArgmax3d`: the module form.

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¢   Fr'   r(   r    ) r   r)   rÆ   rÇ   rÈ   rÉ   r¥   rÊ   r	   rË   r    r"   r   r¨   rC   rÌ   rO   r¼   r¦   rÍ   r5   rÎ   r   r*   r+   Úconv3drG   Ú	transposerÐ   r   rÑ   rÒ   )(r¾   rS   rU   rV   rW   rY   r[   r\   rŽ   rÓ   rÔ   r>   r   r!   r²   r³   r´   rµ   r¶   r·   ÚpzrÕ   rÖ   r"   r   r6   r×   r­   Úd_outrØ   rÙ   rÍ   rÚ   rÛ   rÜ   rÝ   rÞ   rß   rà   rá   s(   &&&&&&&&&                               r   r˜   r˜   ÿ  sÒ  € ðf Ò&Ü!Ô#ä�?Š?˜5×!Ò!ÜÐ@ÄÀeÃÀÐNÓOÐOäˆu�{‰{Ó˜qÔ ÜÐJÈ5Ï;É;È-ÐXÓYÐYä Ô,à—K‘K�M€Aˆ!�Ø�J€BˆBÜ-7¸Ä×-DÒ-D�& &Ñ)È&�J€BˆˆBÜ0:¸7ÄC×0HÒ0H�' GÑ,Èg�J€BˆˆBØ Ÿ<™<€FØŸ™€EØ�M‰M˜!�%  A¨!Ó,€Eä"6°r¸rÀ6Ó"J×"MÑ"MÈeÓ"T€MÜ";¸BÀBÈÓ"O×"RÑ"RÐSXÓ"Y€Mà��R•Ö˜2× ! q¨2¥vÖ"3°×"3¸¸QÀ½VÖ8IÀrÖ8IÜØPÐQXÐPYÐYjÐkvÐjwÐxó
ð 	
ð 	
�€AØ��R•�Z˜"�_ Õ# aÕ'€EØ��R•�Z˜"�_ Õ# aÕ'€EØ��R•�Z˜"�_ Õ# aÕ'€EØˆr�2�r˜2˜rÐ
"€CÜ”q—u’u˜UÕ0°#¼UÀ6»]ÔKÈ[Ð[]Ð_aÐceÐZfÓg€FÜ�mŠm˜F¨Ô*€Gô !2°!°a¸"µfµ*¸aÀ!ÀbÅ&½jÈ!ÈaÐRTÍfÍ*ÐV[ÐdjÔ k€Kà¤§¢¨b°"°b¨\À&ÐP[×PaÑPaÔ bÕb€KØ—.‘. Ó'×/Ñ/°°1°a¸¸AÓ>€KäŸš +¨}ÀbÈ"ÈbÀ\ÔRÐð ×#Ñ# A r¥w°¥|Ó4€GØ˜GÕ#×)Ñ)¨!¨U°A°u¸eÓD×NÑNÈqÐRSÓT€JØÐ0×7Ñ7¸¸1¸eÀUÈEÓRÕR€J÷
 Ü2°:×3EÑ3EÀaÈÈAÈqÐRSÓ3TÐVWÐ\]Ó^ˆ
Ø×'Ñ'¨¨1¨a°°AÓ6ˆ
ð —‘  q¨*¯/©/¸!Ó*<¸j¿o¹oÈaÓ>PÐR\×RaÑRaÐbcÓRdÓe€JçØÐäœŸš˜e SÓ)¨;¸¸RÀ¸ÓE€GØ˜wÕ&×+Ñ+¨AÓ.×3Ñ3°A¸%ÀÈÓN€MØ�}Ð$Ð$r   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   r¾   r$   rW   úOptional[torch.Tensor | float]rY   rZ   r   r   )r   s   "r   r   r   ˜  s,   € ÷ /ñ /Øð/Ø&Dð/Øeið/àñ/r   c                ó2   € \        W4      p\        W24      pV# )að  Compute one soft-argmax (x, y) per heatmap channel over the whole map.

``coords = spatial_soft_argmax2d(heatmap, temperature)`` takes a ``(B, N, H, W)`` heatmap and returns one ``(x, y)``
per channel, ``(B, N, 2)``: the mean pixel position under the softmax of ``heatmap / temperature`` over all
``H x W`` pixels, normalized to :math:`[-1, 1]` by default or in pixels with ``normalized_coordinates=False``. It
is a differentiable mean, not a maximum: it lands on the peak only when the peak dominates the map at the given
temperature, and the rest of the map pulls it away otherwise. For one location per sliding window, use
:func:`conv_soft_argmax2d`.

Convention:
    - Coordinates follow :ref:`Coordinates and sizes <coordinate-conventions>`; this function defaults to
      normalized, corner-aligned coordinates.
    - It is ``spatial_expectation2d(spatial_softmax2d(input, temperature))``: the expected coordinate under the
      softmax of each whole :math:`H \times W` map, so two equal peaks that dominate the map give their midpoint,
      not either peak.

Args:
    input: the given heatmap with shape ``(B, N, H, W)``.
    temperature: softmax temperature: the input is divided by it; smaller is sharper. Must be positive.
      ``None`` means ``1.0``. A tensor temperature is not checked under ``torch.compile`` or export.
    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 expected coordinates of each map with shape ``(B, N, 2)``.

See Also:
    - :func:`spatial_softmax2d`: the softmax step alone, to inspect or reuse the probability maps.
    - :func:`spatial_expectation2d`: the expectation step alone, for maps that already sum to one.
    - :func:`conv_soft_argmax2d`: one soft-argmax per sliding window, for maps with several peaks.
    - :class:`SpatialSoftArgmax2d`: the module form.
    - :func:`render_gaussian2d`: the other direction, a Gaussian probability map around a given ``(x, y)``.

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
   )r¾   rW   rY   Ú
input_softÚoutputs   &&&  r   Úspatial_soft_argmax2drí   ˜  s   € ôZ  1°ÓD€JÜ0°ÓT€FØ€Mr   c                  óN   a € ] tR tRtRtR
R V 3R llltR R ltR R ltR	tV ;t	# )ÚSpatialSoftArgmax2diÊ  a¯  Compute a soft-argmax (x, y) per channel; the module form of spatial_soft_argmax2d.

``op = SpatialSoftArgmax2d(temperature)`` stores the temperature, ``torch.tensor(1.0)`` for ``None``, and
``normalized_coordinates``, and ``coords = op(heatmap)`` returns
``spatial_soft_argmax2d(heatmap, temperature, normalized_coordinates)``: one ``(x, y)`` per channel of a
``(B, N, H, W)`` heatmap, ``(B, N, 2)``, normalized by default.

Convention:
    - See the convention block of :func:`~kornia.geometry.subpix.spatial_soft_argmax2d`.

See Also:
    - :func:`spatial_soft_argmax2d`: the function form.
    - :class:`ConvSoftArgmax2d`: one soft-argmax per sliding window instead of per channel.

c               ó$   € V ^8„  d   QhRRRRRR/# )r   rW   ré   rY   rZ   r   r   r   )r   s   "r   r   Ú SpatialSoftArgmax2d.__annotate__Û  s)   € ÷ Cñ CÐ$Bð CÐcgð CÐswñ Cr   c                	óp   <€ \         SV `  4        Vf   \        P                  ! R4      pWn        W n        R # )Nr0   )r`   ra   r)   r*   rW   rY   )rb   rW   rY   rc   s   &&&€r   ra   ÚSpatialSoftArgmax2d.__init__Û  s.   ø€ Ü‰ÑÔØÒÜŸ,š, sÓ+ˆKØ1<ÔØ,BÖ#r   c               ó   € V ^8„  d   QhRR/# rf   r   )r   s   "r   r   rñ   â  s   € ÷ 
ñ 
˜#ñ 
r   c                	óh   € V P                   P                   R V P                   RV P                   R2# )z(temperature=rk   rl   )rc   rn   rW   rY   ro   s   &r   rp   ÚSpatialSoftArgmax2d.__repr__â  s>   € à�~‰~×&Ñ&Ð'Ø˜D×,Ñ,Ð-ð .&Ø&*×&AÑ&AÐ%BÀ!ðEð	
r   c               ó    € V ^8„  d   QhRRRR/# )r   r¾   r$   r   r   )r   s   "r   r   rñ   é  s   € ÷ [ñ [˜\ð [¨lñ [r   c                óB   € \        WP                  V P                  4      # )aQ  Compute one differentiable 2D coordinate per channel map.

The full spatial map is converted into a probability distribution and
the coordinate expectation is returned. This is a smooth alternative to
taking the hard argmax of each heatmap.

Args:
    input: Heatmap tensor with shape ``(B, C, H, W)``, where
        :math:`B` is batch size, :math:`C` is channel count,
        :math:`H` is height, and :math:`W` is width.

Returns:
    Coordinate tensor from :func:`spatial_soft_argmax2d`. Coordinate
    values are normalized or pixel-based according to
    ``self.normalized_coordinates``.
)rí   rW   rY   )rb   r¾   s   &&r   rz   ÚSpatialSoftArgmax2d.forwardé  s   € ô" % U×,<Ñ,<¸d×>YÑ>YÓZÐZr   )rY   rW   ©NTr�   rˆ   s   @r   rï   rï   Ê  s%   ø† ñ÷ Cò Cõ
÷[ó [r   rï   c               ó@   € V ^8„  d   QhRRRRRRRRRRRRRRR	RR
RRR/
# )r   Údxxr$   ÚdyyÚdssÚdxyÚdxsÚdysÚr0Úr1Úr2r   útuple[torch.Tensor, ...]r   )r   s   "r   r   r   ý  sx   € ÷ +Qñ +QØ	ð+Qà	ð+Qð 
ð+Qð 
ð	+Qð
 
ð+Qð 
ð+Qð 	ð+Qð 	ð+Qð 	ð+Qð ñ+Qr   c	                ó¾  a€ R R lp	\         P                  ! \        P                  ! V P                  4      P
                  4      ) p
V	! WW#WE4      p\        P                  ! \        P                  ! V4      V\        P                  ! V4      4      p\        P                  ! W¹! WgV4      ^?,
          P                  ^ R7      4      P                  V
) V
4      p\        P                  ! VP                  4       4      p\        P                  ! V^ 8„  VP                  4       V4      o\        ;QJ d    . V3R lWW#WEWgV3	 4       F  NK  	  5# ! V3R lWW#WEWgV3	 4       4      # )a,  Scale a Cramer system by the power of two that brings its largest Hessian magnitude to about 1.

On a flat float32 image the Hessian entries are rounding noise of about 1e-15. Their determinants reach float32's
smallest subnormal, and the relative floor ``eps * m**3`` underflows to 0, so tiny determinants count as solved,
their shifts are inaccurate, and the backward of ``num / det``, ``(num / det) / det``, is inf: NaN behind the
callers' masks, which then spreads to every pixel. Scaled, the largest Hessian magnitude is about 1. Cramer's shifts
do not change when H and the right-hand side are scaled together, and a power of two scales every product exactly,
so wherever the unscaled solve neither underflows nor overflows, the shifts and the ``solved`` mask stay the same,
bit for bit. A factor above 1 is capped so that it takes the right-hand side no higher than ``2**64``: a tiny
Hessian next to a large finite right-hand side would otherwise scale it to inf. The cap never scales a system
down, so a large right-hand side alone leaves the system as it is.
c               ó    € V ^8„  d   QhRRRR/# )r   Úentriesr$   r   r   )r   s   "r   r   Ú,_scale_to_unit_hessian.<locals>.__annotate__  s   € ÷ Sñ S˜Lð S¨\ñ Sr   c                 ó  € \         P                  ! V  Uu. uF  qP                  4       NK  	  up4      P                  ^ 4      P	                  4       p\         P
                  ! V4      V^ 8„  ,          p\         P                  ! \         P                  ! \         P                  ! W2\         P                  ! V4      4      4      4      p\         P                  ! W4\         P                  ! V\        P                  ) 4      4      # u upi )r1   )r)   r«   ÚabsÚamaxÚdetachÚisfiniteÚfloorÚlog2ÚwhereÚ	ones_likeÚ	full_likeÚmathÚinf)r  ÚtÚ	magnitudeÚusableÚexponents   *    r   Ú	_exponentÚ)_scale_to_unit_hessian.<locals>._exponent  s¡   € Ü—K’K±'Ó :±'¨Q§¡¦±'Ñ :Ó;×@Ñ@ÀÓC×JÑJÓLˆ	Ü—’ 	Ó*¨i¸!©mÕ<ˆÜ—;’;œuŸzšz¬%¯+ª+°fÌÏÊÐYbÓIcÓ*dÓeÓfˆä�{Š{˜6¬U¯_ª_¸XÌÏÉÀyÓ-QÓRÐRùò	 !;s   •C?)Úmaxc              3  ó4   <"  € T F  qS,          x € K  	  R # 5ir_   r   )Ú.0r  Úfactors   & €r   Ú	<genexpr>Ú)_scale_to_unit_hessian.<locals>.<genexpr>(  s   øé € ÐPÑ%O �V—’Ó%Oùs   ƒ)r  r  r)   Úfinfor   Útinyr  r  Ú
zeros_likeÚmaximumÚclampÚexp2r  Ú
reciprocalÚtuple)rü   rý   rþ   rÿ   r   r  r  r  r  r  ÚlimitÚhessianr  Úpowerr  s   &&&&&&&&&     @r   Ú_scale_to_unit_hessianr-  ý  s  ø€ õ0Sô �YŠY”u—{’{ 3§9¡9Ó-×2Ñ2Ó3Ð3€EÙ˜ #¨CÓ5€GÜ�kŠkœ%Ÿ.š.¨Ó1°7¼E×<LÒ<LÈWÓ<UÓV€Gô �}Š}˜W y°¸Ó'<¸rÕ'A×&HÑ&HÈQÐ&HÓ&OÓP×VÑVÐX]ÐW]Ð_dÓe€Hô �JŠJ�x—|‘|“~Ó&€EÜ�[Š[˜ A™ u×'7Ñ'7Ó'9¸5ÓA€FßŒ5ÔP c°¸#ÀBÈBÑ%OÓP�5ÐPˆ5ÔP c°¸#ÀBÈBÑ%OÓPÓPÐPr   c               óD   € V ^8„  d   Qh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[   r5   r   z=tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]r   )r   s   "r   r   r   +  sw   € ÷ *$ñ *$Ø	ð*$à	ð*$ð 
ð*$ð 
ð	*$ð
 
ð*$ð 
ð*$ð 	ð*$ð 	ð*$ð 	ð*$ð 
ð*$ð Cñ*$r   c
                óÂ  € \         P                  ! \        WW#WEWgV4	      ^4      p
\         P                  ! RV P                  \         P
                  R7      P                  4       pV
P                  ^V4      P                  R^^	4      P                  ^4      w	  rÍrïpppppVVV,          VV,          ,
          ,          WßV,          VV,          ,
          ,          ,
          WïV,          VV,          ,
          ,          ,           pVR,          pV
R,          P                  4       P                  ^RR7      pVP                  4       V	V,          V,          V,          8„  pVR,          \         P                  ! VV\         P                  ! V4      4      ,          p\         P                  ! VV\         P                  ! V4      4      pVP                  ^4      w  pppVVVVR	,          3# )
a›  Evaluate four Cramer determinants together, preserving scalar operation order.

Used only for CUDA float32/float64. Packing trades extra temporary storage for
fewer launches; the scalar implementation is faster on CPU and retains the
float16 solve's promotion behavior.

All inputs must be 1-D tensors of the same length: the packed layout indexes
a single batch dimension and silently reshapes anything wider.
r(   T)Úkeepdim))	r1   r~   é   r~   r2   é   r2  r3  r   )	é   r~   r2  é   r2   r3  é   r3  r   )	r1   r4  r2  r~   r5  r3  r2  r6  r   )	r1   r~   r4  r~   r2   r5  r2  r3  r6  r¤   )r¡   :r1   r2   N)r¡   :Nr4  N)r¡   :r2   NN)r¡   r1   )r)   r«   r-  r*   r"   ÚlongÚflattenÚindex_selectr¨   Úunbindr  r  r  r  r$  )rü   rý   rþ   rÿ   r   r  r  r  r  r[   ÚsystemÚindicesÚarÓ   rÔ   r>   ÚeÚfÚgr   r»   ÚdeterminantsÚdetÚscaleÚsolvedÚshiftsr·   r¶   Ússs   &&&&&&&&&&                   r   Ú_solve_cramer_sym3x3_cudarG  +  sƒ  € ô* �[Š[Ô/°¸#ÀCÈbÐVXÓYÐ[\Ó]€Fä�lŠlð	
ð �z‰zÜ�j‰jô	÷ �gƒið ð !'× 3Ñ 3°A°wÓ ?× GÑ GÈÈAÈqÓ Q× XÑ XÐYZÓ [Ñ€Aˆ!��1�a˜˜AØ˜˜A�  A¥�Õ&¨°!­e°a¸!µe­mÕ)<Õ<¸qÈÅEÈAÐPQÍEÅMÕ?RÕR€LØ
�vÕ
€CØ�5�M×ÑÓ×$Ñ$ Q°Ð$Ó5€EØ�W‰W‹Y˜˜u� uÕ,¨uÕ4Ñ4€FØ˜%Õ ¤5§;¢;¨v°s¼E¿OºOÈCÓ<PÓ#QÕQ€Fä�[Š[˜ ¬×)9Ò)9¸&Ó)AÓB€FØ—‘˜qÓ!�J€BˆˆBØˆr�2�v˜d•|Ð#Ð#r   c               ó    € V ^8„  d   QhRRRR/# )r   Úpatchr$   r   r  r   )r   s   "r   r   r   X  s   € ÷ Hñ H Lð HÐ5Mñ Hr   c                óÐ  € \         P                  ! RV P                  \         P                  R7      pV P	                  ^V4      P                  R^^4      P                  ^4      w  r#rErgRW#,
          ,          pVRV R,          ,          ,
          V,           p	RWE,
          V,
          V,           ,          p
. VP                  ^4      OV	P                  ^4      OV
P                  ^4      O5# )zGPack x/y/scale finite differences from an N x 27 neighbourhood on CUDA.r(   ç      à?ç       @ç      Ð?)é   é   é   é   é
   r2  é   é   é   é   é   é   é   r3  r5  é	   r~   r2   r¤   )r¡   :é   rN  N)r)   r*   r"   r7  r9  r¨   r:  )rI  r<  ÚplusÚminusÚcross_aÚcross_bÚcross_cÚcross_dÚgradientÚdiagonalÚmixeds   &          r   Ú_quadratic_derivatives3dre  X  sÄ   € ä�lŠlØJØ�|‰|Ü�j‰jô€Gð
 7<×6HÑ6HÈÈGÓ6T×6\Ñ6\Ð]_ÐabÐdeÓ6f×6mÑ6mÐnoÓ6pÑ3€D� 7Ø�d•lÕ#€HØ�c˜E (�OÕ+Õ+¨eÕ3€HØ�GÕ%¨Õ/°'Õ9Õ:€EØGˆX�_‰_˜QÓÐG (§/¡/°!Ó"4ÐG°u·|±|ÀA³ÑGÐGr   c               óD   € V ^8„  d   Qh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   s   "r   r   r   f  s„   € ÷ Hñ HØ	ðHà	ðHð 
ðHð 
ð	Hð
 
ðHð 
ðHð 	ðHð 	ðHð 	ðHð 
ðHð CñHr   c
                óZ  a€ V P                   '       dP   V P                  ^8X  d?   V P                  \        P                  \        P
                  39   d   \        WW#WEWgW‰4
      # V P                  p
V
\        P                  8X  dŽ   V P                  4       VP                  4       VP                  4       r!p VP                  4       VP                  4       VP                  4       rTpVP                  4       VP                  4       VP                  4       r‡p\        WW#WEWgV4	      w	  rr#rErgpW,          WU,          ,
          pW2,          WT,          ,
          pW5,          W,          ,
          pW,          W<,          ,
          WM,          ,           p\        P                  ! V P                  4       VP                  4       VP                  4       VP                  4       VP                  4       VP                  4       34      P                  ^ 4      pVP                  4       WŸ,          V,          V,          8„  o\        P                  ! SV\        P                  ! V4      4      pWk,          W7V,          WX,          ,
          ,          ,
          WGV,          W,          ,
          ,          ,           V,          pWV,          WX,          ,
          ,          Wl,          ,
          WCV,          Wt,          ,
          ,          ,           V,          pWV,          Wu,          ,
          ,          W3V,          Wt,          ,
          ,          ,
          Wm,          ,           V,          pV3R lVVV3 4       w  pppV
\        P                  8X  d4   VP                  V
4      VP                  V
4      VP                  V
4      pppVVVS3# )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: relative determinant floor. The system is treated as singular when
        ``|det| <= eps * m**3``, where ``m`` is the largest magnitude among the
        Hessian entries, so the test does not depend on the response amplitude.
        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 * m**3``). The shifts of an unsolved system are 0.
c              3  ó|   <"  € T F1  p\         P                  ! SV\         P                  ! V4      4      x € K3  	  R # 5ir_   )r)   r  r$  )r  r  rD  s   & €r   r   Ú'_solve_cramer_sym3x3.<locals>.<genexpr>ª  s,   øé € ÐTÁ|À!”%—+’+˜f a¬×)9Ò)9¸!Ó)<×=Ð=Ã|ùs   ƒ9<)Úis_cudaÚndimr   r)   Úfloat32Úfloat64rG  Úfloat16r5   r-  r«   r  r  r  r  rÌ   )rü   rý   rþ   rÿ   r   r  r  r  r  r[   Úin_dtypeÚcf00Úcf01Úcf02rB  rC  Úsafe_detr·   r¶   rF  rD  s   &&&&&&&&&&          @r   Ú_solve_cramer_sym3x3rt  f  s�  ø€ ðN ‡{‡{€{�s—x‘x 1”}¨¯©´u·}±}ÄeÇmÁmÐ6TÔ)TÜ(¨°3¸SÀrÈrÓWÐWð �y‰y€HØ”5—=‘=Ô ØŸ	™	› S§Y¡Y£[°#·)±)³+�#ˆØŸ	™	› S§Y¡Y£[°#·)±)³+�#ˆØ—X‘X“Z §¡£¨R¯X©X«Z�ˆÜ/EÀcÐPSÐZ]ÐdfÐlnÓ/oÑ,€Cˆc˜ "¨"à�9�s•yÕ €DØ�9�s•yÕ €DØ�9�s•yÕ €DØ
�*�s•zÕ
! C¥JÕ
.€Cô �KŠK˜Ÿ™› C§G¡G£I¨s¯w©w«y¸#¿'¹'»)ÀSÇWÁWÃYÐPS×PWÑPWÓPYÐZÓ[×`Ñ`ÐabÓc€EØ�W‰W‹Y˜� uÕ,¨uÕ4Ñ4€Fä�{Š{˜6 3¬¯ª¸Ó(<Ó=€HØ
�)�c #�X¨­Õ0Õ1Õ
1°CÀ½8ÀcÅhÕ;NÕ4OÕ
OÐS[Õ	[€BØ
�c•˜C�HÕ$Õ
%¨­	Õ
1°CÀ½8ÀbÅhÕ;NÕ4OÕ
OÐS[Õ	[€BØ
�r•˜B�HÕ$Õ
%¨°R­x¸"½(Õ/BÕ(CÕ
CÀbÅiÕ
OÐS[Õ	[€Bô UÈÈBÐPRÁ|ÓT�J€BˆˆBà”5—=‘=Ô Ø—U‘U˜8“_ b§e¡e¨H£o°r·u±u¸X³�ˆBˆØˆr�2�vÐÐr   c               ó8   € V ^8„  d   QhRRRRRRRRR	R
RRRRRR/# )r   r¾   r$   Ún_itersr    rŽ   r�   Úmax_subpixel_shiftr5   Úprecomputed_nms_maskúOptional[torch.Tensor]Údilation_radiusÚallow_scale_stepsrZ   r   ú!tuple[torch.Tensor, torch.Tensor]r   )r   s   "r   r   r   ±  sb   € ÷ vñ vØðvàðvð )ðvð ð	vð
 1ðvð ðvð ðvð 'ñvr   c                óÖ  € Ve   \        4        \        P                  ! V 4      '       g   \        R\	        V 4       24      hV P
                  ^8w  d   \        RV P                   24      hV P                  w  rxršpV P                  pV P                  pWx,          pWš,          V,          pW«,          p\        P                  ! Wx^WšW¼VR7      p\        P                  ! WœVR7      P                  V	^^4      VR&   \        P                  ! W¼VR7      P                  ^^V4      VR&   \        P                  ! W¬VR7      P                  ^V
^4      VR&   V P                  4       pV	^8  g   V
^8  g   V^8  d   VV3# Ve   TM\        V RR4      p\        P                  ! VP!                  WéW«4      4      w  ppppVP                  ^ ,          pTp\        P                  ! V) V^,           V\        P"                  R7      p\        P$                  ! VVVRR7      w  pppVP!                  R4      pVP!                  R4      pVP!                  R4      pVP                  ^ ,          pVP'                  ^4      VP'                  ^ 4      ,           P!                  R4      pVP'                  ^4      VP'                  ^ 4      ,           P!                  R4      p VP'                  ^4      VP'                  ^ 4      ,           P!                  R4      p!VP'                  ^4      P)                  RV4      P!                  R4      p"V^8¬  VV	^,
          8*  ,          V ^8¬  ,          V V
^,
          8*  ,          V!^8¬  ,          V!V^,
          8*  ,          p#V"V#,          p$VV#,          p%V V#,          p&V!V#,          p'V P!                  R4      p(\*        P-                  V4      V,          \.        P-                  V4      V,          ,           \0        P-                  V4      ,           p)V$V,          V%V,          ,           V&V,          ,           V',           p*V(V*P'                  ^4      V)P'                  ^ 4      ,           ,          p+V P2                  '       d=   V\        P4                  \        P6                  39   d   \9        V+4      w	  p,p-p.p/p0p1p2p3p4EMzV+R,          p5V+R,          p6V+R,          p7V+R,          p8V+R,          p9V+R,          p:V+R,          p;V+R,          p<V+R,          p=V+R,          p>V+R,          p?V+R,          p@V+R,          pAV+R,          pBV+R ,          pCV+R!,          pDV+R",          pEV+R#,          pFV+R$,          pGRV7V6,
          ,          p,RV9V8,
          ,          p-RV;V:,
          ,          p.V7RV5,          ,
          V6,           p/V9RV5,          ,
          V8,           p0V;RV5,          ,
          V:,           p1R	V?V>,
          V=,
          V<,           ,          p2R	VCVB,
          VA,
          V@,           ,          p3R	VGVF,
          VE,
          VD,           ,          p4\;        V/V0V1V2V3V4V,) V-) V.) 4	      w  pHpIpJpKV,VH,          V-VI,          ,           V.VJ,          ,           pLV$P                  ^ ,          pM\        P<                  ! Wï,          3R\        P>                  VR
7      pN\        P                  ! VM\        P>                  VR
7      VNV$V,          V%V,          ,           V&V,          ,           V',           &   VP                  4       pOVP                  4       pPVP                  4       pQ\        P@                  ! V\        PB                  VR
7      pR\        PD                  ! VWÍR7      pS\        PD                  ! VWÍR7      pT\        PD                  ! VWÍR7      pU\        PD                  ! VWÍR7      pV\        PD                  ! V\        PB                  VR
7      pW\G        V4       EF  pXXOPI                  ^V	^,
          4      pYXPPI                  ^V
^,
          4      pZXQPI                  ^V^,
          4      p[VV,          VYV,          ,           VZV,          ,           V[,           p\XNV\,          P#                  4       p]V]^ 8¬  p^V]PI                  ^ R7      p_XHV_,          p`XIV_,          paXJV_,          pbXLV_,          pcXKV_,          V^,          pdXRVd,          pRVRP-                  V4      peV`Ve,          p`VaVe,          paVbVe,          pb\        P                  ! VRV`XS4      pS\        P                  ! VRVaXT4      pT\        P                  ! VRVbXU4      pU\        P                  ! VRVcXV4      pVVRV`V8„  ,          pfVRV`V) 8  ,          pgVfVg,          pWVQVfP#                  4       ,           VgP#                  4       ,
          phVRVh^8¬  ,          VhV^,
          8*  ,          pRVhPI                  ^ V^,
          4      pQVRVaV8„  ,          piVRVaV) 8  ,          pjVWVi,          Vj,          pWVPViP#                  4       ,           VjP#                  4       ,
          pkVRVk^8¬  ,          VkV
^,
          8*  ,          pRVkPI                  ^ V
^,
          4      pPV'       g   EKŒ  XRXbV8„  ,          plVRVbV) 8  ,          pmXWVl,          Vm,          pWXOVlP#                  4       ,           VmP#                  4       ,
          pnVRVn^8¬  ,          VnV	^,
          8*  ,          pRVnPI                  ^ V	^,
          4      pOEK  	  XRXW( ,          XSPK                  4       R8*  ,          XTPK                  4       R8*  ,          XUPK                  4       R8*  ,          pRVV,          poVV,          pp\        P                  ! VRXOP-                  V4      VU,           VP-                  V4      4      VVoVp^ VVV3&   \        P                  ! VRXQP-                  V4      VS,           VP-                  V4      4      VVoVp^VVV3&   \        P                  ! VRXPP-                  V4      VT,           VP-                  V4      4      VVoVp^VVV3&   R\        P                  ! VRXV\        PL                  ! VV4      4      ,          pq\        P                  ! VRVOV4      pO\        P                  ! VRVPV4      pP\        P                  ! VRVQV4      pQV(P                  WéW«4      VVOVPVQ3,          prVrVq,           VVoVpVVV3&   VV3# )%u³  Refine 3D scale-space maxima by quadratic fit, precomputing the solve near each maximum.

``coords, values = conv_quad_interp3d(response)`` takes a ``(B, C, D, H, W)`` scale-space response, with the scale
levels along ``D``, finds its strict ``3 x 3 x 3`` maxima with :func:`nms3d` (or reads ``precomputed_nms_mask``),
and returns for every voxel its ``(d, x, y)`` coordinates, ``(B, C, 3, D, H, W)``, and its value,
``(B, C, D, H, W)``; only the refined maxima move off their grid index and change value. It solves the fit once
for every voxel within ``dilation_radius`` of a maximum and then follows the moves by table lookup, which suits
CUDA; :func:`iterative_quad_interp3d` solves again at each maximum on every iteration with no radius limit, which
suits the CPU, and :class:`AdaptiveQuadInterp3d` picks between the two by device.

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 of the **dilated NMS neighbourhood**, an
L\ :math:`\infty` ball of radius ``dilation_radius`` around each maximum.  The
iteration loop that follows contains **no data-dependent Python control flow**
and no GPUâ†’CPU synchronisation. Finding the maxima and their neighbourhoods,
with ``torch.where`` on the mask and boolean indexing, does depend on the data:
on CUDA it synchronises with the host, and a default ``torch.compile`` breaks
the graph there; with ``torch._dynamo.config.capture_dynamic_output_shape_ops``
enabled, as :class:`~kornia.feature.ScaleSpaceDetector` does when it compiles
its subpix module, it is captured in one graph.

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) covers almost all of them.  Use ``dilation_radius=2`` (:math:`5^3 = 125`) for
extra safety.  Setting it to ``n_iters`` gives the result of
:func:`iterative_quad_interp3d`, but is much slower on large images.

Convention:
    - ``coords_max`` follows :ref:`Coordinates and sizes <coordinate-conventions>` and holds absolute voxel
      indices of the input: only refined maxima move off their own grid index. At a refined maximum ``y_max`` is
      the quadratic fit's value at the refined point; non-maxima keep their input value.
    - A maximum is not refined, and keeps its grid coordinates, when the determinant of its fit's Hessian is at
      most ``1e-7 * m**3`` in magnitude, where ``m`` is the largest magnitude among the Hessian entries (so the
      test does not depend on the response amplitude), when a move would reach the border voxels, when its centre
      leaves the voxels precomputed for ``dilation_radius``, when the final shift exceeds ``1.5`` voxels on any
      axis, or when it still requires an integer-centre move on the last iteration. A volume with a side shorter
      than 3 is returned unrefined.

Args:
    input: response pyramid with shape ``(B, C, D, H, W)``.
    n_iters: maximum number of localization iterations per keypoint. A keypoint that still moves on the
        last iteration has not converged and is rejected: it keeps its grid coordinates and input value.
    strict_maxima_bonus: deprecated since kornia 0.9.0 and ignored; passing it emits a
        :class:`DeprecationWarning`. Select strict maxima with ``precomputed_nms_mask`` or
        :func:`~kornia.geometry.subpix.nms3d` instead.
    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
        ``(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 move farther are rejected, keeping their grid coordinates
        and input value, unless the voxels they reach were precomputed for
        another maximum.
    allow_scale_steps: if ``True`` (default), the integer centre may also move
        along the scale (depth) axis; set to ``False`` to keep the integer centre
        on its original scale level. The sub-voxel scale shift is applied either way.

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

    * ``coords_max`` â€” shape ``(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 ``(B, C, D, H, W)``, quadratically corrected
      response at each NMS maximum; other positions keep the input value.

Raises:
    TypeError: if ``input`` is not a tensor.
    ValueError: if ``input`` is not 5D.

See Also:
    - :func:`iterative_quad_interp3d`: solves again at each maximum on every iteration, with no radius limit and
      an optional ``max_candidates`` cap; faster on the CPU.
    - :class:`AdaptiveQuadInterp3d`: by default runs this function on CUDA and :func:`iterative_quad_interp3d`
      elsewhere.
    - :class:`ConvQuadInterp3d`: the module form.
    - :func:`nms3d`: the strict maxima this function refines; pass its mask as ``precomputed_nms_mask``.
    - :func:`conv_soft_argmax3d`: a softmax-weighted position in every window instead of a quadratic fit at the
      maxima.

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À   ú.Invalid input shape, expected BxCxDxHxW. Got: r(   TÚij)ÚindexingrK  rL  rM  ©r   r"   )Úminç      ø?©r¡   r¡   r1   ©r¡   r¡   r2   ©r¡   r¡   r   r›   r¤   ©r¡   r[  ©r¡   rQ  ©r¡   rN  ©r¡   rR  ©r¡   rO  ©r¡   r2  ©r¡   rP  ©r¡   rZ  ©r¡   rY  ©r¡   rV  ©r¡   rS  ©r¡   r~   ©r¡   r3  ©r¡   rW  ©r¡   rT  ©r¡   r2   ©r¡   r5  ©r¡   rX  ©r¡   rU  )'r   r)   rÆ   rÇ   rÈ   rk  rÊ   r¥   r"   r   ÚemptyrF   rG   Úcloner   r  r¨   r7  ÚmeshgridrK   rÐ   Ú	_PATCH_DDrÌ   Ú	_PATCH_DHÚ	_PATCH_DWrj  rl  rm  re  rt  ÚfullÚint32ÚonesrZ   r4   r¬   r&  r  r$  )sr¾   rv  rŽ   rw  rx  rz  r{  Ú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_flatrI  ÚgxÚgyÚgsrü   rý   rþ   rÿ   r   r  Ú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Ú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Úmovedr®   ÚdiÚhiÚwiÚflat_qÚlut_idxÚin_lutÚidx_safer·   r¶   rF  Ú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_centerss   &&&&&&&                                                                                                            r   Úconv_quad_interp3dr  ±  sÎ
  € ðX Ò&Ü!Ô#Ü�?Š?˜5×!Ò!ÜÐ@ÄÀeÃÀÐNÓOÐOØ‡z�z�Q„ÜÐIÈ%Ï+É+ÈÐWÓXÐXà—K‘K�M€Aˆ!�Ø�\‰\€FØ�K‰K€EØ	
�€BØ
�%�!�)€CØ	
�€Bä—’˜Q 1 a¨AÀEÔJ€JÜŸ,š, q¸uÔE×JÑJÈ1ÈaÐQRÓS€JˆwÑÜŸ,š, q¸uÔE×JÑJÈ1ÈaÐQRÓS€JˆwÑÜŸ,š, q¸uÔE×JÑJÈ1ÈaÐQRÓS€JˆwÑØ�K‰K‹M€Eàˆ1„u��A”˜˜QœØ˜5Ð Ð ð (<Ò'GÑ#ÌUÐSXÐZcÐeiÓMj€HÜ"'§+¢+¨h×.>Ñ.>¸rÀaÓ.KÓ"LÑ€FˆE�5˜%Ø�‰�Q�€Að 	€AÜ�<Š<˜˜˜A �E¨&¼¿
¹
ÔC€DÜ—’  d¨D¸4Ô@�J€Bˆˆ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Ñ6°rÓ:€Fð �Q‰J˜5 A¨¥E™>Õ*¨e°q©jÕ9¸UÀaÈ!Åe¹^ÕLÐPUÐYZÑPZÕ[Ð_dÐhiÐlmÕhmÑ_mÕn€DØ�$�<€DØ
��+€CØ
��+€CØ
��+€Cð �}‰}˜RÓ €HÜ—L‘L Ó(¨2Õ-´	·±¸VÓ0DÀqÕ0HÕHÌ9Ï<É<ÐX^ÓK_Õ_€MØ˜•*˜s R�xÕ'¨#°­'Õ1°CÕ7€KØ�[×*Ñ*¨1Ó-°×0GÑ0GÈÓ0JÕJÕK€Eð ‡}‡}€}˜¤5§=¡=´%·-±-Ð"@Ô@Ü3KÈEÓ3RÑ0ˆˆB��C˜˜c 3¨ªSà�U�|ˆØ�U�|ˆØ�U�|ˆØ�U�|ˆØ�U�|ˆØ�T�{ˆØ�U�|ˆØ˜•+ˆØ˜•,ˆØ˜•,ˆØ˜•,ˆØ˜•+ˆØ˜•+ˆØ˜•,ˆØ˜•,ˆØ˜•+ˆØ˜•+ˆØ˜•,ˆØ˜•,ˆð �D˜4•KÕ ˆØ�D˜4•KÕ ˆØ�D˜4•KÕ ˆØ�S˜4•ZÕ $Õ&ˆØ�S˜4•ZÕ $Õ&ˆØ�S˜4•ZÕ $Õ&ˆØ�g Õ'¨'Õ1°GÕ;Õ<ˆØ�g Õ'¨'Õ1°GÕ;Õ<ˆØ�g Õ'¨'Õ1°GÕ;Õ<ˆä2°3¸¸SÀ#ÀsÈCÐRTÐQTÐWYÐVYÐ\^Ð[^Ó_Ñ€Dˆ$��eà��I˜˜T�	Õ! B¨¥IÕ-€Eð 
�‰�A�€BÜ
�*Š*�b•h�[ "¬E¯K©KÀÔ
G€CÜ16·²¸bÌÏÉÐ\bÔ1c€Cˆˆs�
�S˜2•XÕ  a¥Õ'¨#Õ-Ñ.ð �K‰K‹M€EØ�K‰K‹M€EØ�K‰K‹M€EÜ�JŠJ�q¤§
¡
°6Ô:€EÜ�kŠk˜! FÔ8€GÜ�kŠk˜! FÔ8€GÜ�kŠk˜! FÔ8€GÜ—[’[ ¨6Ô?€NÜ�KŠK˜¤§¡°FÔ;€Eä�7�^ˆØ�[‰[˜˜A �EÓ"ˆØ�[‰[˜˜A �EÓ"ˆØ�[‰[˜˜A �EÓ"ˆà˜#•  R¥Õ'¨"¨q­&Õ0°2Õ5ˆØ�f•+×"Ñ"Ó$ˆØ˜A‘ˆØ—=‘= Q�=Ó'ˆà�(�^ˆØ�(�^ˆØ�(�^ˆØ�H�oˆØ�H�o Õ&ˆà˜•ˆØ�X‰X�e‹_ˆØ�"�WˆØ�"�WˆØ�"�Wˆä—+’+˜e R¨Ó1ˆÜ—+’+˜e R¨Ó1ˆÜ—+’+˜e R¨Ó1ˆÜŸš U¨C°Ó@ˆà˜2Ð 2Ñ2Õ3ˆØ˜2Ð!3Ð 3Ñ3Õ4ˆØ˜'Õ!ˆØ˜Ÿ™›Õ&¨¯©«Õ7ˆØ˜ !™Õ$¨°°Qµ©Õ7ˆØ—‘˜A˜q 1�uÓ%ˆà˜2Ð 2Ñ2Õ3ˆØ˜2Ð!3Ð 3Ñ3Õ4ˆØ˜• 'Õ)ˆØ˜Ÿ™›Õ&¨¯©«Õ7ˆØ˜ !™Õ$¨°°Qµ©Õ7ˆØ—‘˜A˜q 1�uÓ%ˆçÒØ˜rÐ$6Ñ6Õ7ˆGØ˜rÐ%7Ð$7Ñ7Õ8ˆGØ˜G•O gÕ-ˆEØ˜GŸL™L›NÕ*¨W¯\©\«^Õ;ˆEØ˜U a™ZÕ(¨E°Q¸µU©NÕ;ˆEØ—K‘K  1 q¥5Ó)‹Eñ_ ðf �U�F�N˜gŸk™k›m¨sÑ2Õ3°w·{±{³}ÈÑ7KÕLÐPW×P[ÑP[ÓP]ÐadÑPdÕe€Eð �a�K€EØ�Q�J€Eä7<·{²{À5È%Ï(É(ÐSXË/Ð\cÕJcÐej×emÑemÐnsÓetÓ7u€Jˆu�e˜Q  u¨eÐ3Ñ4Ü7<·{²{À5È%Ï(É(ÐSXË/Ð\cÕJcÐej×emÑemÐnsÓetÓ7u€Jˆu�e˜Q  u¨eÐ3Ñ4Ü7<·{²{À5È%Ï(É(ÐSXË/Ð\cÕJcÐej×emÑemÐnsÓetÓ7u€Jˆu�e˜Q  u¨eÐ3Ñ4àœ5Ÿ;š; u¨n¼e×>NÒ>NÈ~Ó>^Ó_Õ_€Nä�KŠK˜˜u eÓ,€EÜ�KŠK˜˜u eÓ,€EÜ�KŠK˜˜u eÓ,€EØ—‘˜r aÓ+¨F°E¸5À%Ð,GÕH€JØ/9¸NÕ/J€Eˆ%�˜˜u eÐ
+Ñ,à�uÐÐr   c                  óR   a € ] tR tRtRtR
R V 3R llltR R ltRR R lltR	tV ;t	# )ÚConvQuadInterp3diê  u»  Refine scale-space maxima by quadratic fit; the module form of conv_quad_interp3d.

``op = ConvQuadInterp3d(n_iters, max_subpixel_shift=0.6, dilation_radius=1)`` stores the arguments, and
``coords, values = op(response, precomputed_nms_mask)`` returns what :func:`conv_quad_interp3d` returns for them:
the ``(B, C, 3, D, H, W)`` refined ``(d, x, y)`` coordinates and the ``(B, C, D, H, W)`` values of a
``(B, C, D, H, W)`` response.

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; finding the maxima still
synchronises, as :func:`~kornia.geometry.subpix.conv_quad_interp3d` describes.

Convention:
    - See the convention block of :func:`~kornia.geometry.subpix.conv_quad_interp3d`.

Args:
    n_iters: maximum localization iterations per keypoint.
    strict_maxima_bonus: deprecated since kornia 0.9.0 and ignored; passing it emits a
        :class:`DeprecationWarning`.
    max_subpixel_shift: shift threshold that triggers integer centre move.
    dilation_radius: radius of the precomputed neighbourhood, as in
        :func:`~kornia.geometry.subpix.conv_quad_interp3d`.
    allow_scale_steps: whether the integer centre may move along the scale axis, as in
        :func:`~kornia.geometry.subpix.conv_quad_interp3d`.

See Also:
    - :func:`conv_quad_interp3d`: the function form.
    - :class:`IterativeQuadInterp3d`: the module that solves again at each maximum on every iteration.
    - :class:`AdaptiveQuadInterp3d`: the module that picks this backend or the iterative one by device.

c               ó0   € V ^8„  d   QhRRRRRRRRRR	R
R/# )r   rv  r    rŽ   r�   rw  r5   rz  r{  rZ   r   r   r   )r   s   "r   r   ÚConvQuadInterp3d.__annotate__  sF   € ÷ 3ñ 3àð3ð -ð3ð "ð	3ð
 ð3ð  ð3ð 
ñ3r   c                	óp   <€ \         SV `  4        Ve   \        4        Wn        W0n        W@n        WPn        R # r_   )r`   ra   r   rv  rw  rz  r{  )rb   rv  rŽ   rw  rz  r{  rc   s   &&&&&&€r   ra   ÚConvQuadInterp3d.__init__  s3   ø€ ô 	‰ÑÔØÒ*Ü%Ô'ØŒØ"4ÔØ.ÔØ!2Ör   c               ó   € V ^8„  d   QhRR/# rf   r   )r   s   "r   r   r    ó   € ÷ 
ñ 
˜#ñ 
r   c           
     	óœ   € V P                   P                   R V P                   RV P                   RV P                   RV P
                   R2
# )ú	(n_iters=ú, max_subpixel_shift=ú, dilation_radius=ú, allow_scale_steps=rl   )rc   rn   rv  rw  rz  r{  ro   s   &r   rp   ÚConvQuadInterp3d.__repr__  s_   € à�~‰~×&Ñ&Ð'ð (Ø—|‘|�nð %"Ø"&×"9Ñ"9Ð!:ð ;Ø#×3Ñ3Ð4ð 5!Ø!%×!7Ñ!7Ð 8¸ð	;ð	
r   c               ó$   € V ^8„  d   QhRRRRRR/# ©r   ru   r$   rx  ry  r   r|  r   )r   s   "r   r   r  %  s$   € ÷ 
ñ 
Øð
Ø5Kð
à	*ñ
r   c           	     ót   € \        VV P                  V P                  VV P                  V P                  R7      # )a¾  Refine 3D extrema by quadratic interpolation, with the solve precomputed near each maximum.

The method starts from local maxima in a scale-space response volume
and fits a local quadratic model around each candidate. The fitted
offset gives a subpixel position in scale, x, and y coordinates.

Args:
    x: Response tensor with shape ``(B, C, D, H, W)``, where
        :math:`D` is the scale/depth dimension.
    precomputed_nms_mask: Optional boolean NMS mask with the same shape
        as ``x``. Passing it avoids recomputing local maxima.

Returns:
    Tuple ``(coords, values)``. ``coords`` stores refined coordinates
    for scale, x, and y; ``values`` stores the corrected response
    scores.
©rw  rx  rz  r{  )r  rv  rw  rz  r{  ©rb   ru   rx  s   &&&r   rz   ÚConvQuadInterp3d.forward%  s9   € ô( "ØØ�L‰LØ#×6Ñ6Ø!5Ø ×0Ñ0Ø"×4Ñ4ô
ð 	
r   )r{  rz  rw  rv  )r3  Nç333333ã?r2   Tr_   r�   rˆ   s   @r   r  r  ê  s"   ø† ñ÷B3ò 3õ 
÷
õ 
r   r  c               ó8   € V ^8„  d   QhRRRRRRRRR	R
RRRRRR/# )r   r¾   r$   rv  r    rŽ   r�   rw  r5   r{  rZ   rx  ry  Úmax_candidatesúOptional[int]r   r|  r   )r   s   "r   r   r   C  sb   € ÷ Dñ DØðDàðDð )ðDð ð	Dð
 ðDð 1ðDð "ðDð 'ñDr   c                ó@  € Ve   \        4        \        P                  ! V 4      '       g   \        R\	        V 4       24      hV P
                  ^8w  d   \        RV P                   24      hVe   V^ 8  d   \        RV 24      hV P                  w  rxršpV P                  pV P                  p\        P                  ! Wx^WšW¼VR7      p\        P                  ! WœVR7      P                  V	^^4      VR&   \        P                  ! W¼VR7      P                  ^^V4      VR&   \        P                  ! W¬VR7      P                  ^V
^4      VR&   V P                  4       pV	^8  g   V
^8  g   V^8  d   Wï3# V P                  Wx,          WšV4      pWš,          V,          pW«,          pVe   TM\        V RR4      P                  Wx,          WšV4      p\        P                   ! V4      w  ppppVP                  ^ ,          pVEe
   VV8”  Ed   VVVVV3,          p\        P"                  ! VRRR7      pV\        P"                  ! VV,          RR7      ,          p\        P$                  ! VWx,          R7      p\        P&                  ! V^ 4      V,
          p\        P                  ! VVR	7      VVV,          ,          ,
          pVVV8  ,          pVV,          pVV,          pVV,          pVV,          p\)        VP                  ^ ,          4      p\*        P-                  V4      V,          \.        P-                  V4      V,          ,           \0        P-                  V4      ,           p VP                  4       p!VP                  4       p"VP                  4       p#\        P2                  ! V\        P4                  VR
7      p$\        P6                  ! VWÍR7      p%\        P6                  ! VWÍR7      p&\        P6                  ! VWÍR7      p'\        P6                  ! VWÍR7      p(\        P6                  ! V\        P4                  VR
7      p)VP                  R4      p*VV,          p+\9        V4       EFà  p,V!P;                  ^V	^,
          4      p-V"P;                  ^V
^,
          4      p.V#P;                  ^V^,
          4      p/V*V+V-V,          ,           V.V,          ,           V/,           P=                  ^4      V P=                  ^ 4      ,           ,          p0V P>                  '       d=   V\        P@                  \        PB                  39   d   \E        V04      w	  p1p2p3p4p5p6p7p8p9EMzV0R,          p:V0R,          p;V0R,          p<V0R,          p=V0R,          p>V0R,          p?V0R,          p@V0R,          pAV0R,          pBV0R,          pCV0R,          pDV0R,          pEV0R ,          pFV0R!,          pGV0R",          pHV0R#,          pIV0R$,          pJV0R%,          pKV0R&,          pLRV<V;,
          ,          p1RV>V=,
          ,          p2RV@V?,
          ,          p3V<RV:,          ,
          V;,           p4V>RV:,          ,
          V=,           p5V@RV:,          ,
          V?,           p6RVDVC,
          VB,
          VA,           ,          p7RVHVG,
          VF,
          VE,           ,          p8RVLVK,
          VJ,
          VI,           ,          p9\G        V4V5V6V7V8V9V1) V2) V3) 4	      w  pMpNpOpPV$VP,          p$V$P-                  V4      pQVMVQ,          pMVNVQ,          pNVOVQ,          pO\        P                   ! V$VMV%4      p%\        P                   ! V$VNV&4      p&\        P                   ! V$VOV'4      p'\        P                   ! V$V1VM,          V2VN,          ,           V3VO,          ,           V(4      p(V$VMV8„  ,          pRV$VMV) 8  ,          pSVRVS,          p)V#VRPI                  4       ,           VSPI                  4       ,
          pTV$VT^8¬  ,          VTV^,
          8*  ,          p$VTP;                  ^ V^,
          4      p#V$VNV8„  ,          pUV$VNV) 8  ,          pVV)VU,          VV,          p)V"VUPI                  4       ,           VVPI                  4       ,
          pWV$VW^8¬  ,          VWV
^,
          8*  ,          p$VWP;                  ^ V
^,
          4      p"V'       g   EKU  V$XOV8„  ,          pXV$VOV) 8  ,          pYV)VX,          VY,          p)V!VXPI                  4       ,           VYPI                  4       ,
          pZV$VZ^8¬  ,          VZV	^,
          8*  ,          p$VZP;                  ^ V	^,
          4      p!EKã  	  V$V)( ,          V%PK                  4       R8*  ,          V&PK                  4       R8*  ,          V'PK                  4       R8*  ,          p$VV,          p[VV,          p\\        P                   ! V$V!P-                  V4      V',           VP-                  V4      4      p]\        P                   ! V$V#P-                  V4      V%,           VP-                  V4      4      p^\        P                   ! V$V"P-                  V4      V&,           VP-                  V4      4      p_V]VV[V\^ VVV3&   V^VV[V\^VVV3&   V_VV[V\^VVV3&   R\        P                   ! V$V(\        PL                  ! V(4      4      ,          p`\        P                   ! V$V!V4      p!\        P                   ! V$V"V4      p"\        P                   ! V$V#V4      p#VVV!V"V#3,          paVaV`,           VV[V\VVV3&   Wï3# )'uq  Refine 3D scale-space maxima by quadratic fit, re-solving at each maximum per iteration.

``coords, values = iterative_quad_interp3d(response)`` takes a ``(B, C, D, H, W)`` scale-space response and returns
what :func:`conv_quad_interp3d` returns: for every voxel its ``(d, x, y)`` coordinates, ``(B, C, 3, D, H, W)``, and
its value, ``(B, C, D, H, W)``, moved and corrected only at the refined strict ``3 x 3 x 3`` maxima. It works on
the maxima alone, with no precomputed neighbourhood, so a maximum is not limited to a radius around its start, and
``max_candidates`` caps the work per ``(b, c)`` map; it is the faster choice on the CPU, and
:func:`conv_quad_interp3d` on CUDA.

Unlike :func:`conv_quad_interp3d`, which pre-computes the Hessian solve for the
voxels near 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.

Convention:
    - See the convention block of :func:`conv_quad_interp3d`; here a maximum is not limited to a
      ``dilation_radius`` neighbourhood.

Args:
    input: response pyramid with shape ``(B, C, D, H, W)``.
    n_iters: maximum number of localization iterations per keypoint. A keypoint that still moves on the
        last iteration has not converged and is rejected: it keeps its grid coordinates and input value.
    strict_maxima_bonus: deprecated since kornia 0.9.0 and ignored; passing it emits a
        :class:`DeprecationWarning`. Select strict maxima with ``precomputed_nms_mask`` or
        :func:`~kornia.geometry.subpix.nms3d` instead.
    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 integer centre may also move
        along the scale (depth) axis; set to ``False`` to keep the integer centre
        on its original scale level. The sub-voxel scale shift is applied either way.
    precomputed_nms_mask: optional bool tensor of shape
        ``(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 of each ``(b, c)`` map (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.  Must be non-negative; ``0`` refines nothing.

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

    * ``coords_max`` has shape ``(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 ``(B, C, D, H, W)`` and stores the quadratically
      corrected response values.

Raises:
    TypeError: if ``input`` is not a tensor.
    ValueError: if ``input`` is not 5D or ``max_candidates`` is negative.

See Also:
    - :func:`conv_quad_interp3d`: precomputes the solve within ``dilation_radius`` of each maximum and follows the
      moves by lookup; faster on CUDA.
    - :class:`AdaptiveQuadInterp3d`: by default runs this function except on CUDA.
    - :class:`IterativeQuadInterp3d`: the module form.
    - :func:`nms3d`: the strict maxima this function refines; pass its mask as ``precomputed_nms_mask``.

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~  z*max_candidates must be non-negative. Got: r(   T)Ú
descendingÚstable)r  )Ú	minlengthr'   r�  rK  rL  rM  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È   rk  rÊ   r¥   r"   r   rš  rF   rG   r›  r¨   r   r  ÚargsortÚbincountÚcumsumr    r�  rÌ   rž  rŸ  r¢  rZ   r4   r¬   r&  rK   rj  rl  rm  re  rt  r7  r  r$  )br¾   rv  rŽ   rw  r{  rx  r  r£  r¤  r¥  r¦  r§  r"   r   rß   r«  Úinpr©  rª  Únms_flatr­  r®  r¯  r°  r±  Ú	cand_valsÚby_valueÚgroupedÚcountsÚ	row_startÚrankr¼  rÂ  rá  râ  rã  rä  rå  ræ  rç  rè  ré  rÁ  Úbc_baser®   Úd_sÚh_sÚw_srI  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¶   rF  rD  Úvalid_fÚ
move_pos_xÚ
move_neg_xrö  Ú
move_pos_yÚ
move_neg_yrù  Ú
move_pos_sÚ
move_neg_srü  rý  rþ  Úfinal_sÚfinal_xÚfinal_yrÿ  r   sb   &&&&&&&                                                                                           r   Úiterative_quad_interp3dr7  C  sd	  € ðd Ò&Ü!Ô#Ü�?Š?˜5×!Ò!ÜÐ@ÄÀeÃÀÐNÓOÐOØ‡z�z�Q„ÜÐIÈ%Ï+É+ÈÐWÓXÐXØÒ! n°qÔ&8ÜÐEÀnÐEUÐVÓWÐWà—K‘K�M€Aˆ!�Ø�\‰\€FØ�K‰K€Eä—’˜Q 1 a¨AÀEÔJ€JÜŸ,š, q¸uÔE×JÑJÈ1ÈaÐQRÓS€JˆwÑÜŸ,š, q¸uÔE×JÑJÈ1ÈaÐQRÓS€JˆwÑÜŸ,š, q¸uÔE×JÑJÈ1ÈaÐQRÓS€JˆwÑØ�K‰K‹M€Eàˆ1„u��A”˜˜QœØÐ Ð à
�-‰-˜�˜q QÓ
'€CØ
�%�!�)€CØ	
�€Bà(<Ò(HÑ$ÌeÐTYÐ[dÐfjÓNk×tÑtØ	�ˆq�Qó€Hô #(§+¢+¨hÓ"7Ñ€FˆE�5˜%Ø�‰�Q�€Að Ó! a¨.Õ&8Ø˜  u¨eÐ3Õ4ˆ	ô —=’= °tÀDÔIˆØœ5Ÿ=š=¨°Õ)9À$ÔGÕHˆÜ—’ °!µ%Ô8ˆÜ—L’L ¨Ó+¨fÕ4ˆ	Ü�|Š|˜A fÔ-°	¸&À½/Õ0JÕJˆØ�t˜nÑ,Õ-ˆØ˜•ˆØ�d•ˆØ�d•ˆØ�d•ˆÜ�—
‘
˜1•Óˆä—L‘L Ó(¨2Õ-´	·±¸VÓ0DÀqÕ0HÕHÌ9Ï<É<ÐX^ÓK_Õ_€Mà�K‰K‹M€EØ�K‰K‹M€EØ�K‰K‹M€Eä�JŠJ�q¤§
¡
°6Ô:€Eä�kŠk˜! FÔ8€GÜ�kŠk˜! FÔ8€GÜ�kŠk˜! FÔ8€GÜ—[’[ ¨6Ô?€NÜ�KŠK˜¤§¡°FÔ;€Eà�{‰{˜2‹€HØ�s�l€Gä�7�^ˆØ�k‰k˜!˜Q �UÓ#ˆØ�k‰k˜!˜Q �UÓ#ˆØ�k‰k˜!˜Q �UÓ#ˆà˜' C¨"¥HÕ,¨s°Q­wÕ6¸Õ<×GÑGÈÓJÈ]×MdÑMdÐefÓMgÕgÕhˆà�=�=ˆ=˜U¤u§}¡}´e·m±mÐ&DÔDÜ7OÐPUÓ7VÑ4ˆB��B˜˜S # s¨C²à˜•<ˆDØ˜•<ˆDØ˜•<ˆDØ˜•<ˆDØ˜•<ˆDØ˜•;ˆDØ˜•<ˆDØ˜D•kˆGØ˜E•lˆGØ˜E•lˆGØ˜E•lˆGØ˜D•kˆGØ˜D•kˆGØ˜E•lˆGØ˜E•lˆGØ˜D•kˆGØ˜D•kˆGØ˜E•lˆGØ˜E•lˆGà˜˜t�Õ$ˆBØ˜˜t�Õ$ˆBØ˜˜t�Õ$ˆBà˜˜t�Õ# dÕ*ˆCØ˜˜t�Õ# dÕ*ˆCØ˜˜t�Õ# dÕ*ˆCØ˜' GÕ+¨gÕ5¸Õ?Õ@ˆCØ˜' GÕ+¨gÕ5¸Õ?Õ@ˆCØ˜' GÕ+¨gÕ5¸Õ?Õ@ˆCä1°#°s¸CÀÀcÈ3ÐQSÐPSÐVXÐUXÐ[]ÐZ]Ó^ÑˆˆB��FØ˜•ˆà—(‘(˜5“/ˆØ�'�\ˆØ�'�\ˆØ�'�\ˆä—+’+˜e R¨Ó1ˆÜ—+’+˜e R¨Ó1ˆÜ—+’+˜e R¨Ó1ˆÜŸš U¨B°­G°b¸2µgÕ,=ÀÀRÅÕ,GÈÓXˆà˜bÐ#5Ñ5Õ6ˆ
Ø˜bÐ$6Ð#6Ñ6Õ7ˆ
Ø˜ZÕ'ˆØ˜
Ÿ™Ó)Õ)¨J¯O©OÓ,=Õ=ˆØ˜ !™Õ$¨°°Qµ©Õ7ˆØ—‘˜A˜q 1�uÓ%ˆà˜bÐ#5Ñ5Õ6ˆ
Ø˜bÐ$6Ð#6Ñ6Õ7ˆ
Ø˜
Õ" ZÕ/ˆØ˜
Ÿ™Ó)Õ)¨J¯O©OÓ,=Õ=ˆØ˜ !™Õ$¨°°Qµ©Õ7ˆØ—‘˜A˜q 1�uÓ%ˆçÒØ "Ð'9Ñ"9Õ:ˆJØ "Ð(:Ð':Ñ":Õ;ˆJØ˜JÕ&¨Õ3ˆEØ˜JŸO™OÓ-Õ-°
·±Ó0AÕAˆEØ˜U a™ZÕ(¨E°Q¸µU©NÕ;ˆEØ—K‘K  1 q¥5Ó)‹EñU ð\ �U�F�N˜gŸk™k›m¨sÑ2Õ3°w·{±{³}ÈÑ7KÕLÐPW×P[ÑP[ÓP]ÐadÑPdÕe€Eà�a�K€EØ�Q�J€Eä�kŠk˜% §¡¨%£°7Õ!:¸E¿H¹HÀU»OÓL€GÜ�kŠk˜% §¡¨%£°7Õ!:¸E¿H¹HÀU»OÓL€GÜ�kŠk˜% §¡¨%£°7Õ!:¸E¿H¹HÀU»OÓL€Gà7>€Jˆu�e˜Q  u¨eÐ3Ñ4Ø7>€Jˆu�e˜Q  u¨eÐ3Ñ4Ø7>€Jˆu�e˜Q  u¨eÐ3Ñ4àœ5Ÿ;š; u¨n¼e×>NÒ>NÈ~Ó>^Ó_Õ_€Nä�KŠK˜˜u eÓ,€EÜ�KŠK˜˜u eÓ,€EÜ�KŠK˜˜u eÓ,€EØ�V˜U E¨5Ð0Õ1€JØ/9¸NÕ/J€Eˆ%�˜˜u eÐ
+Ñ,àÐÐr   c                  óR   a € ] tR tRtRtR
R V 3R llltR R ltRR R lltR	tV ;t	# )ÚIterativeQuadInterp3diJ  aŒ  Refine scale-space maxima by quadratic fit; the module form of iterative_quad_interp3d.

``op = IterativeQuadInterp3d(n_iters, max_subpixel_shift=0.6, max_candidates=None)`` stores the arguments, and
``coords, values = op(response, precomputed_nms_mask)`` returns what :func:`iterative_quad_interp3d` returns for
them: the ``(B, C, 3, D, H, W)`` refined ``(d, x, y)`` coordinates and the ``(B, C, D, H, W)`` values of a
``(B, C, D, H, W)`` response. Passing ``strict_maxima_bonus`` emits a :class:`DeprecationWarning` and has no
effect.

Convention:
    - See the convention block of :func:`~kornia.geometry.subpix.iterative_quad_interp3d`.

See Also:
    - :func:`iterative_quad_interp3d`: the function form.
    - :class:`ConvQuadInterp3d`: the module that precomputes the solve near each maximum.
    - :class:`AdaptiveQuadInterp3d`: the module that picks this backend or the precomputing one by device.

c               ó0   € V ^8„  d   QhRRRRRRRRR	R
RR/# )r   rv  r    rŽ   r�   rw  r5   r{  rZ   r  r  r   r   r   )r   s   "r   r   Ú"IterativeQuadInterp3d.__annotate__]  sF   € ÷ -ñ -àð-ð -ð-ð "ð	-ð
  ð-ð &ð-ð 
ñ-r   c                	óp   <€ \         SV `  4        Ve   \        4        Wn        W0n        W@n        WPn        R # r_   )r`   ra   r   rv  rw  r{  r  )rb   rv  rŽ   rw  r{  r  rc   s   &&&&&&€r   ra   ÚIterativeQuadInterp3d.__init__]  s3   ø€ ô 	‰ÑÔØÒ*Ü%Ô'ØŒØ"4ÔØ!2ÔØ,Ör   c               ó   € V ^8„  d   QhRR/# rf   r   )r   s   "r   r   r;  m  r	  r   c           
     	óœ   € V P                   P                   R V P                   RV P                   RV P                   RV P
                   R2
# )r  r  r  ú, max_candidates=rl   )rc   rn   rv  rw  r{  r  ro   s   &r   rp   ÚIterativeQuadInterp3d.__repr__m  s_   € à�~‰~×&Ñ&Ð'ð (Ø—|‘|�nð %"Ø"&×"9Ñ"9Ð!:ð ;!Ø!%×!7Ñ!7Ð 8ð 9Ø"×1Ñ1Ð2°!ð	5ð	
r   c               ó$   € V ^8„  d   QhRRRRRR/# r  r   )r   s   "r   r   r;  v  s(   € ÷ 
ñ 
àð
ð 5ð
ð 
+ñ	
r   c           	     ót   € \        VV P                  V P                  V P                  VV P                  R7      # )a¢  Refine 3D extrema by iteratively fitting local quadratic patches.

Args:
    x: Response tensor with shape ``(B, C, D, H, W)``.
    precomputed_nms_mask: Optional boolean local-maxima mask with the
        same shape as ``x``.

Returns:
    Tuple ``(coords, values)`` from :func:`iterative_quad_interp3d`.
    ``coords`` contains refined scale, x, and y locations, while
    ``values`` contains their response scores.
©rw  r{  rx  r  )r7  rv  rw  r{  r  r  s   &&&r   rz   ÚIterativeQuadInterp3d.forwardv  s9   € ô" 'ØØ�L‰LØ#×6Ñ6Ø"×4Ñ4Ø!5Ø×.Ñ.ô
ð 	
r   )r{  r  rw  rv  )r3  Nr  TNr_   r�   rˆ   s   @r   r9  r9  J  s!   ø† ñ÷$-ò -õ 
÷
õ 
r   r9  c                  óV   a € ] tR tRtRtR
tRR V 3R llltR R ltRR R lltR	t	V ;t
# )ÚAdaptiveQuadInterp3di‘  uÉ  Refine 3D scale-space maxima by quadratic fit with the faster backend for the device.

``op = AdaptiveQuadInterp3d(mode="auto")`` stores the arguments of both backends, and
``coords, values = op(response, precomputed_nms_mask)`` calls :func:`conv_quad_interp3d` with ``mode="conv"``, or
with ``mode="auto"`` for an input on CUDA, and :func:`iterative_quad_interp3d` otherwise (``mode="patch"``, or
``"auto"`` on any other device). Both return the ``(B, C, 3, D, H, W)`` refined ``(d, x, y)`` coordinates and the
``(B, C, D, H, W)`` values of a ``(B, C, D, H, W)`` response. With ``max_candidates`` unset they agree on every
maximum whose centre stays within ``dilation_radius`` voxels of its start; beyond that the conv backend may
reject a maximum the iterative one refines, so CPU and CUDA keypoints can differ, and ``dilation_radius=n_iters``
makes the two backends agree. It is the default ``subpix_module`` of :class:`~kornia.feature.ScaleSpaceDetector`.

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``.

Convention:
    - See the convention block of :func:`~kornia.geometry.subpix.conv_quad_interp3d`.

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: deprecated since kornia 0.9.0 and ignored; passing it emits a
        :class:`DeprecationWarning`.
    max_subpixel_shift: integer-centre move threshold.
    dilation_radius: L\ :math:`\infty` precompute radius for ``"conv"`` mode
        (ignored in ``"patch"`` mode).
    allow_scale_steps: whether the integer centre may move along the scale axis, in both modes.
    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`).

Raises:
    ValueError: if ``mode`` is not ``"patch"``, ``"conv"`` or ``"auto"``.

See Also:
    - :func:`conv_quad_interp3d`: the backend on CUDA, with a ``dilation_radius`` limit.
    - :func:`iterative_quad_interp3d`: the backend elsewhere, with an optional ``max_candidates`` cap.
    - :class:`ConvQuadInterp3d`: the conv backend alone, as a module.
    - :class:`IterativeQuadInterp3d`: the iterative backend alone, as a module.

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])

c               ó8   € V ^8„  d   QhRRRRRRRRR	RR
RRRRR/# )r   Úmoderg   rv  r    rŽ   r�   rw  r5   rz  r{  rZ   r  r  r   r   r   )r   s   "r   r   Ú!AdaptiveQuadInterp3d.__annotate__Î  sZ   € ÷ -ñ -àð-ð ð-ð -ð	-ð
 "ð-ð ð-ð  ð-ð &ð-ð 
ñ-r   c                	óà   <€ \         SV `  4        Ve   \        4        WP                  9  d   \	        RV P                   RV R24      hWn        W n        W@n        WPn        W`n	        Wpn
        R # )Nzmode must be one of z, got 'Ú')r`   ra   r   ÚMODESrÊ   rI  rv  rw  rz  r{  r  )	rb   rI  rv  rŽ   rw  rz  r{  r  rc   s	   &&&&&&&&€r   ra   ÚAdaptiveQuadInterp3d.__init__Î  sg   ø€ ô 	‰ÑÔØÒ*Ü%Ô'Ø—z‘zÔ!ÜÐ3°D·J±J°<¸wÀtÀfÈAÐNÓOÐOØŒ	ØŒØ"4ÔØ.ÔØ!2ÔØ,Ör   c               ó   € V ^8„  d   QhRR/# rf   r   )r   s   "r   r   rJ  ä  s   € ÷ 	
ñ 	
˜#ñ 	
r   c                	óÐ   € V P                   P                   R V P                   RV P                   RV P                   RV P
                   RV P                   RV P                   R2# )z(mode='z', n_iters=r  r  r  r@  rl   )rc   rn   rI  rv  rw  rz  r{  r  ro   s   &r   rp   ÚAdaptiveQuadInterp3d.__repr__ä  s~   € à�~‰~×&Ñ&Ð'ð (Ø—Y‘Y�Kð  Ø—|‘|�nð %"Ø"&×"9Ñ"9Ð!:ð ;Ø#×3Ñ3Ð4ð 5!Ø!%×!7Ñ!7Ð 8ð 9Ø"×1Ñ1Ð2°!ð5ð	
r   c               ó$   € V ^8„  d   QhRRRRRR/# r  r   )r   s   "r   r   rJ  ï  s(   € ÷ %
ñ %
àð%
ð 5ð%
ð 
+ñ	%
r   c           	     ój  € V P                   R8H  ;'       g$    V P                   R8H  ;'       d    VP                  pV'       d:   \        VV P                  V P                  VV P
                  V P                  R7      # \        VV P                  V P                  V P                  VV P                  R7      # )a  Refine 3D extrema with the selected interpolation backend.

The backend is chosen according to ``self.mode`` (or device when
``mode='auto'``), then delegated to either
:func:`conv_quad_interp3d` or :func:`iterative_quad_interp3d`.

Args:
    x: Response tensor with shape ``(B, C, D, H, W)``.
    precomputed_nms_mask: Optional boolean local-maxima mask with the
        same shape as ``x``.

Returns:
    Tuple ``(coords, values)`` containing refined scale-space
    coordinates and corresponding response scores.
ÚconvÚautor  rD  )	rI  rj  r  rv  rw  rz  r{  r7  r  )rb   ru   rx  Úuse_convs   &&& r   rz   ÚAdaptiveQuadInterp3d.forwardï  sž   € ð( —9‘9 Ñ&×MÐM¨4¯9©9¸Ñ+>×+LÐ+LÀ1Ç9Á9ˆßÜ%ØØ—‘Ø#'×#:Ñ#:Ø%9Ø $× 4Ñ 4Ø"&×"8Ñ"8ôð ô 'ØØ�L‰LØ#×6Ñ6Ø"×4Ñ4Ø!5Ø×.Ñ.ô
ð 	
r   )r{  rz  r  rw  rI  rv  )rI  rT  rU  )rU  r3  Nr  r2   TNr_   )rn   r‚   rƒ   r„   r…   rM  ra   rp   rz   r†   r‡   rˆ   s   @r   rG  rG  ‘  s)   ø† ñ8ðt &€E÷-ò -õ,	
÷%
õ %
r   rG  )r¤   r¤   r¤   r¤   r¤   r¤   r¤   r¤   r¤   r1   r1   r1   r1   r1   r1   r1   r1   r1   r2   r2   r2   r2   r2   r2   r2   r2   r2   )r¤   r¤   r¤   r1   r1   r1   r2   r2   r2   r¤   r¤   r¤   r1   r1   r1   r2   r2   r2   r¤   r¤   r¤   r1   r1   r1   r2   r2   r2   )r¤   r1   r2   r¤   r1   r2   r¤   r1   r2   r¤   r1   r2   r¤   r1   r2   r¤   r1   r2   r¤   r1   r2   r¤   r1   r2   r¤   r1   r2   r_   r}   rš   rú   )gH¯¼šò×z>)r3  Nr  Nr2   T)r3  Nr  TNN)3r…   Ú
__future__r   r  r   Útypingr   r)   Útorch.nn.functionalr   Ú
functionalr¦   Úkornia.geometry.conversionsr   r   Úkornia.geometry.gridr   r   Údsntr	   r
   r   Únmsr   r*   r7  r�  rž  rŸ  r   r-   r;   rC   rO   ÚModulerQ   rŠ   r¼   rx   r˜   rí   rï   r-  rG  re  rt  r  r  r7  r9  rG  r   r   r   Ú<module>ra     sN  ðñ$ nå "ã Û Ý ã ß Ð Ý ç bß Cç WÑ WÝ ð �LŠLÚ^Ø
�*‰*ô€	ð �LŠLÚ^Ø
�*‰*ô€	ð �LŠLÚ^Ø
�*‰*ô€	õ÷-÷(÷B%÷P3ô.L
�r—y‘yô L
ô^K
�r—y‘yô K
õ\b÷,T%÷nV%÷r/ôd0[˜"Ÿ)™)ô 0[õf+Q÷\*$õZH÷H÷Vvôr	V
�r—y‘yô V
÷rDôND
˜BŸI™Iô D
ôNC
˜2Ÿ9™9ö C
r   