+
    åûj�t  ã                  óê   € R t ^ RIH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 ^ RIHtHtHtHt ^ RIHtHtHtHtHt ^ R	IHtHtHt ^ R
IH t   ! R R]PB                  4      t"R# )z<Pyramid-based SIFT extraction at sparse local affine frames.)ÚannotationsN)ÚTuple)Únn)ÚKORNIA_CHECK_LAFÚKORNIA_CHECK_SHAPE)Ú_l2_normalize)Ú_grid_sample_patchesÚ_promoted_grid_dtypeÚlaf_is_validÚ
rotate_laf)Ú%_dense_sift_histograms_from_gradientsÚ_exact_first_order_gradientÚ_gradient_magnitude_orientationÚ	_rootsiftÚget_sift_pooling_kernel)Úgaussian_blur2dÚget_gaussian_discrete_kernel1dÚget_gaussian_kernel2d)Úpyrdownc                  ó  a € ] tR t^0tRtRR V 3R lllt]R R l4       tR R R llt]R R	 l4       t	]R
 R l4       t
]R R l4       tR R lt]R R l4       tR R ltR R ltR R ltR R ltR R ltR!R R lltRtV ;t# )"ÚSIFTDescriptorFromPyramida0  Describe given LAFs with SIFT from a shared gradient pyramid, without sampling patches.

``sift = SIFTDescriptorFromPyramid()``, then ``descs = sift(image, lafs)`` takes grayscale images
``(B, 1, H, W)`` and their already oriented LAFs ``(B, N, 2, 3)`` in pixels and returns one descriptor per LAF,
``(B, N, num_ang_bins * num_spatial_bins ** 2)``: ``(B, N, 128)`` by default, in the image dtype, RootSIFT by
default, in kornia's angle-major layout. ``lafs, descs = sift.orient_and_describe(image, lafs)`` also gives each
LAF the orientation of its dominant gradient first, sharing one pyramid between the two steps. Each LAF reads
histograms pooled at one octave of a pyramid that this module builds from ``image``, not reused from a detector:
it describes the square ``c + A [-1, 1]^2`` that :class:`SIFTDescriptor` sees in the patch of
:func:`extract_patches_from_pyramid`, without sampling that patch, so its values approximate those of
:class:`SIFTDescriptor` without equalling them. For the patch descriptors themselves, use
``LAFDescriptor(SIFTDescriptor(41), patch_size=41)`` (:class:`LAFDescriptor`) instead. :class:`SIFTFeature`'s
``"patch"`` backend uses that descriptor, and its ``"pyramid"`` backend uses this module.

The performance and accuracy acceptance criteria of its automatic
orientation are tracked in
`#5748 <https://github.com/kornia/kornia/issues/5748>`_. See
:ref:`sift-descriptor-interfaces` for the distinct patch, dense-map and
supplied-frame descriptor contracts.

The module combines the shared histogram maps of `VLFeat DSIFT
<https://www.vlfeat.org/api/dsift.html>`_ with orientation-relative spatial and
angular binning as in OpenCV's `SIFT implementation
<https://github.com/opencv/opencv/blob/4.x/modules/features2d/src/sift.simd.hpp>`_:
descriptor gradients are binned once at each pyramid octave. Orientation uses
a separate gradient field, smoothed with a one-pixel Gaussian at each octave,
and integrates 19x19 gradient samples with a Gaussian of sigma one third of
the LAF scale. Gradients are transformed into the frame before orientation
histogramming, avoiding interpolation of already quantized angular bins.
Unlike patch-wise SIFT, no image patch is resampled before either stage.

For a general affine LAF the global angular bins are remapped through the
LAF's ``A.T`` gradient pullback, including its direction-dependent magnitude.
This makes affine frames useful without extracting patches, but is an
approximation: a histogram bin represents every gradient in its angular
interval by its centre direction, and spatial pooling is performed in the
image pyramid before the affine footprint is sampled.

Convention:
    - ``lafs`` use the pixel convention of ``image``, with the layout of
      :func:`~kornia.feature.laf_from_center_scale_ori` (see :ref:`Local features <local-features-conventions>`).
      Cell ``(i, j)`` of the ``num_spatial_bins`` x ``num_spatial_bins`` grid is centred at ``c + A (u_j, u_i)``
      with ``u_k = (2 k + 1) / num_spatial_bins - 1``, at whichever octave the LAF selects: the cell centres of a
      ``num_spatial_bins``-pixel patch from :func:`~kornia.feature.extract_patches_from_pyramid`, row 0 on the
      frame's :math:`-y` side.
    - :meth:`orient_and_describe`, unless ``upright=True``, rotates each valid frame so that its dominant
      gradient, measured in the frame's own coordinates, points along the frame's :math:`+x` axis, whatever
      orientation the frame had. This is the orientation convention of :class:`~kornia.feature.LAFOrienter`, and it
      puts that gradient direction in the descriptor's angle bin 0.
    - A frame that :func:`~kornia.feature.laf_is_valid` rejects, such as the all-zero padding LAF, gets an all-zero
      descriptor, with or without RootSIFT, and :meth:`orient_and_describe` returns the frame unchanged.
      :class:`~kornia.feature.SIFTDescriptor` instead describes the flat patch that a zero LAF extracts by ``1e-5``
      in every entry with RootSIFT.
    - Clipping, RootSIFT (the default) and kornia's angle-major layout are those of
      :class:`~kornia.feature.SIFTDescriptor`, whose Convention block gives them;
      :func:`~kornia.feature.convert_sift_descriptor_layout` reorders the descriptors to OpenCV's.

Args:
    num_ang_bins: Number of descriptor angular bins.
    num_spatial_bins: Number of descriptor spatial bins per axis.
    spatial_bin_size: Side of the DenseSIFT spatial pooling window, in pixels.
        The default 8 approximately matches the 19-pixel octave support to the patch SIFT
        descriptor's 17-pixel pooling bins at its default 41-pixel patch.
    rootsift: If ``True``, apply RootSIFT after clipping and normalization.
    clipval: Descriptor clipping threshold.
    orientation_bins: Number of bins for dominant-orientation assignment.
        Independent of the descriptor's global histogram resolution (at least 36
        bins), which is remapped to ``num_ang_bins`` in each local frame.

Shape:
    - image: ``(B, 1, H, W)``
    - lafs: ``(B, N, 2, 3)`` in image pixel coordinates
    - descriptors: ``(B, N, num_ang_bins * num_spatial_bins ** 2)``

See Also:
    - :class:`SIFTDescriptor`: SIFT descriptors of given patches, such as those sampled from LAFs.
    - :class:`LAFDescriptor`: the patch alternative for the same image and LAFs, with the exact values of a
      :class:`SIFTDescriptor` on a patch sampled per LAF, as in the ``"patch"`` backend of :class:`SIFTFeature`.
    - :class:`DenseSIFTDescriptor`: a SIFT descriptor at every position of an image, at one scale.
    - :func:`convert_sift_descriptor_layout`: reorders the descriptors into OpenCV's layout.
    - :class:`LAFOrienter`: orients LAFs from their patches, before a patch descriptor.
    - :class:`SIFTFeature`: detects DoG keypoints and, with ``descriptor_backend="pyramid"``, orients and
      describes them with :meth:`orient_and_describe`.

Example:
    >>> image = torch.rand(1, 1, 64, 64)
    >>> xy, scale = torch.tensor([[[32.0, 32.0]]]), torch.full((1, 1, 1, 1), 8.0)
    >>> lafs = kornia.feature.laf_from_center_scale_ori(xy, scale)
    >>> SIFTDescriptorFromPyramid()(image, lafs).shape
    torch.Size([1, 1, 128])

c               ó4   € V ^8„  d   QhRRRRRRRRRRR	RR
R/# )é   Únum_ang_binsÚintÚnum_spatial_binsÚspatial_bin_sizeÚrootsiftÚboolÚclipvalÚfloatÚorientation_binsÚreturnÚNone© )Úformats   "ÚWC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\feature\sift\pyramid.pyÚ__annotate__Ú&SIFTDescriptorFromPyramid.__annotate__Ž   sP   € ÷ 
ñ 
àð
ð ð
ð ð	
ð
 ð
ð ð
ð ð
ð 
ñ
ó    c           	     	ó
  <€ \         S	V `  4        V^8  g   V^8  g   V^8  g   V^8  d   \        R4      hWn        W n        W0n        W@n        WPn        W`n        \        ^$V4      V n
        RV n        \        V4      P                  ^^W34      pV P                  RV4       \        RRR4      pV P                  RVP                  ^^^^4      RR7       V P                  R\!        ^R	4      P                  ^^^4      RR7       R
# )r   zZSIFT bin counts and spatial_bin_size must be positive (angular bin counts need at least 2)g»½×Ùß|Û=Údescriptor_pooling_kernelTÚorientation_weightingF)Ú
persistentÚorientation_smoothinggš™™™™™ù?N)é   r/   )çUUUUUU	@r0   )ÚsuperÚ__init__Ú
ValueErrorr   r   r   r   r   r!   ÚmaxÚ_descriptor_binsÚepsr   ÚreshapeÚregister_bufferr   r   )
Úselfr   r   r   r   r   r!   ÚpoolingÚ	weightingÚ	__class__s
   &&&&&&&  €r&   r2   Ú"SIFTDescriptorFromPyramid.__init__Ž   s  ø€ ô 	‰ÑÔØ˜!ÔÐ/°!Ô3Ð7GÈ!Ô7KÐO_ÐbcÔOcÜØlóð ð )ÔØ 0ÔØ 0ÔØ ŒØŒØ 0ÔÜ # B¨Ó 5ˆÔØˆŒÜ)Ð*:Ó;×CÑCÀAÀqÐJZÓmˆØ×ÑÐ8¸'ÔBô *¨(Ð4LÈdÓSˆ	Ø×ÑÐ4°i×6GÑ6GÈÈ1ÈbÐRTÓ6UÐbgÐÔhØ×ÑØ#Ô%CÀAÀsÓ%K×%SÑ%SÐTUÐWXÐZ[Ó%\Ðinð 	ö 	
r)   c               ó    € V ^8„  d   QhRRRR/# )r   Úimageútorch.Tensorr"   r   r$   )r%   s   "r&   r'   r(   ¯   s   € ÷ ñ  <ð °Cñ r)   c                ó„   € V P                   RR w  r^p\        W4      ^&8¼  d   V^,          V^,          r!V^,          pK,  V# )zHReturn the number of octaves ``_pyramid`` would construct for ``image``.Néþÿÿÿ)ÚshapeÚmin)r?   ÚheightÚwidthÚlevelss   &   r&   Ú_num_pyramid_levelsÚ-SIFTDescriptorFromPyramid._num_pyramid_levels®   sE   € ð Ÿ™ B CÐ(‰ˆØˆÜ�&Ó  BÔ&Ø" a�K¨°!­�EØ�a�KŠFØˆr)   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r?   r@   Ú
num_levelsz
int | Noner"   úlist[torch.Tensor]r$   )r%   s   "r&   r'   r(   ¸   s"   € ÷ ñ ˜lð ¸
ð ÐN`ñ r)   c                óÂ   € V.p\        VR,          P                  RR 4      ^&8¼  d8   Ve   \        V4      V8  d$   VP                  \	        VR,          4      4       K[  V# )z:Build at most ``num_levels`` octaves of the image pyramid.NéÿÿÿÿrB   )rD   rC   ÚlenÚappendr   )r9   r?   rK   rG   s   &&& r&   Ú_pyramidÚ"SIFTDescriptorFromPyramid._pyramid¸   sR   € à�ˆÜ�&˜•*×"Ñ" 2 3Ð'Ó(¨BÔ.°JÒ4FÌ#ÈfË+ÐXbÔJbØ�M‰Mœ' &¨¥*Ó-Ö.Øˆr)   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )r   Úmapsr@   Úlevel_imageÚlafsÚ
patch_sizer   r"   r$   )r%   s   "r&   r'   r(   À   s8   € ÷ añ a�lð a°ð aÀ\ð aÐ_bð aÐgsñ ar)   c                	óÀ  € VP                   R ,          w  rEV^ 8X  d,   V P                  V^ V P                   ^,          W3,          4      # R\        P                  ! W2P                  VP
                  R7      ,          R,           V,          R,
          p\        P                  ! WfRR7      w  rx\        P                  ! W‡.R
R7      P                  ^^W3^4      p	\        P                  ! RVR,          V	R,          4      VR,          P                  WE^^^4      ,           p
VP                   RR w  r¼RV
R	,           ,          V
P                  WË.4      ,          R,
          pVP                  WEV,          V^4      p\        V P
                  VP
                  4      pV P
                  V8w  d   V P                  V4      MT pVP
                  V8w  d   VP                  V4      MTp\        WýVP                   R,          VP                   R
,          4      P                  V P
                  4      pVP                  W@P                   ^,          WSV,          4      P                  ^ ^^^4      # )ºNr   Nç       @©ÚdeviceÚdtypeç      ð?Úij)Úindexing©Údimzbnij,xyj->bnxyiNç      à?rN   ©.rY   rY   )é    re   ).rY   r   rB   )rC   Ú	new_zerosÚtorchÚaranger\   r]   ÚmeshgridÚstackr7   ÚeinsumÚviewÚ
new_tensorr	   Útor   Úpermute)rT   rU   rV   rW   ÚbÚnÚcoordinatesÚyyÚxxÚlocalÚpointsÚhÚwÚgridÚ
grid_dtypeÚsample_mapsÚsampleds   &&&&             r&   Ú_sampleÚ!SIFTDescriptorFromPyramid._sample¿   sá  € à�z‰z˜"�~‰ˆØ�Œ6Ø—>‘> ! Q¨¯
©
°1­°zÕ7NÓOÐOØœUŸ\š\¨*¿[¹[ÐPT×PZÑPZÔ[Õ[Ð^aÕaÐeoÕoÐruÕuˆÜ—’ À4ÔH‰ˆÜ—’˜R˜H¨"Ô-×5Ñ5°a¸¸JÐTUÓVˆÜ—’Ð/°°kÕ1BÀEÈ$ÅKÓPÐSWÐXbÕSc×ShÑShÐijÐopÐrsÐuvÓSwÕwˆØ× Ñ   Ð%‰ˆØ�f˜s•lÕ# f×&7Ñ&7¸¸Ó&?Õ?À#ÕEˆØ�|‰|˜A :�~¨z¸1Ó=ˆÜ)¨$¯*©*°d·j±jÓAˆ
Ø-1¯Z©Z¸:Ô-E�d—g‘g˜jÔ)È4ˆØ&*§j¡j°JÔ&>ˆt�w‰w�zÔ"ÀDˆÜ& {¸+×:KÑ:KÈBÕ:OÐQ\×QbÑQbÐceÕQfÓg×jÑjÐko×kuÑkuÓvˆØ�‰˜q§*¡*¨Q¥-°ÀÕ4KÓL×TÑTÐUVÐXYÐ[\Ð^_Ó`Ð`r)   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   Ú
histogramsr@   ÚaffineÚoutput_binsr   r"   r$   )r%   s   "r&   r'   r(   Ò   s*   € ÷ 'ñ ' ,ð '¸ð 'ÐSVð 'Ð[gñ 'r)   c           	     óœ  € V P                   w  r4rVV P                  p\        V P                  VP                  4      pV P                  V4      p VP                  V4      p\        P
                  ! WPP                  V P                  R7      p	R\        P                  ,          V	,          \        V4      ,          p	\        P                  ! \        P                  ! V	4      \        P                  ! V	4      .RR7      p
\        P                  ! RW4      p\        P                  P                  VRR7      p\        P                   ! VR,          VR,          4      pVR\        P                  ,          ,          \        V4      ,          R\        P                  ,          ,          p\        P"                  ! V4      P%                  4       V,          pV^,           V,          pV\        P"                  ! V4      ,
          pWP'                  R4      ,          pV P)                  W4W&4      pVP+                  ^VP'                  R4      P-                  RRRV4      VRV,
          P'                  R4      ,          4       VP+                  ^VP'                  R4      P-                  RRRV4      VVP'                  R4      ,          4       VP                  V4      # )	zAMove globally binned gradients into each LAF's local coordinates.©r]   r\   rZ   ra   zbnji,kj->bnkir^   rN   ).é   ).re   )rC   r]   r	   rn   rg   rh   r\   ÚmathÚpir    rj   ÚcosÚsinrk   ÚlinalgÚvector_normÚatan2ÚfloorÚlongÚ	unsqueezerf   Úscatter_add_Úexpand)r€   r�   r‚   rp   rq   Úsource_binsÚsamplesÚoutput_dtypeÚworking_dtypeÚanglesÚ
directionsÚtransformedÚ	magnitudeÚlocal_angleÚpositionÚlowerÚupperÚupper_weightÚvaluesÚoutputs   &&&                 r&   Ú_remap_anglesÚ'SIFTDescriptorFromPyramid._remap_anglesÑ   s  € ð &0×%5Ñ%5Ñ"ˆˆkØ!×'Ñ'ˆÜ,¨Z×-=Ñ-=¸v¿|¹|ÓLˆØ—]‘] =Ó1ˆ
Ø—‘˜=Ó)ˆÜ—’˜k×1AÑ1AÈ*×J[ÑJ[Ô\ˆØ”t—w‘w• Õ'¬%°Ó*<Õ<ˆÜ—[’[¤%§)¢)¨FÓ"3´U·Y²Y¸vÓ5FÐ!GÈRÔPˆ
Ü—l’l ?°FÓGˆÜ—L‘L×,Ñ,¨[¸bÐ,ÓAˆ	Ü—k’k +¨fÕ"5°{À6Õ7JÓKˆØ 3¬¯©¥=Õ1´U¸;Ó5GÕGÈ3ÔQU×QXÑQXÍ=ÕYˆÜ—’˜HÓ%×*Ñ*Ó,¨{Õ:ˆØ˜•˜kÕ)ˆØ¤%§+¢+¨hÓ"7Õ7ˆØ×1Ñ1°"Ó5Õ5ˆØ×%Ñ% a¨KÓAˆØ×ÑØˆu�‰˜rÓ"×)Ñ)¨"¨b°"°gÓ>ÀÈ#ÐP\ÕJ\×IgÑIgÐhjÓIkÕ@kô	
ð 	×Ñ˜A˜uŸ™¨rÓ2×9Ñ9¸"¸bÀ"ÀgÓNÐPVÐYe×YoÑYoÐprÓYsÕPsÔtØ�y‰y˜Ó&Ð&r)   c               ó$   € V ^8„  d   QhRRRRRR/# )r   rG   r@   rK   r   r"   z
list[bool]r$   )r%   s   "r&   r'   r(   ì   s!   € ÷ ;ñ ; ð ;¸3ð ;À:ñ ;r)   c                óT  € \         P                  ! V\         P                  V P                  R7      pVP	                  ^ V P                  ^ 4      P                  R4      V ^ 8¬  P                  4       P                  R4      4       VP                  4        Uu. uF  q3^ 8„  NK	  	  up# u upi )zÁReport which octaves at least one valid LAF selects.

``levels`` holds ``-1`` for invalid frames. A single host transfer
answers both which octaves carry work and how high the pyramid reaches.
r„   rN   )rg   ÚzerosrŽ   r\   r�   Ú	clamp_minr7   Útolist)rG   rK   Ú	occupancyÚcounts   &&  r&   Ú_level_occupancyÚ*SIFTDescriptorFromPyramid._level_occupancyë   s„   € ô —K’K 
´%·*±*ÀVÇ]Á]ÔSˆ	Ø×Ñ˜q &×"2Ñ"2°1Ó"5×"=Ñ"=¸bÓ"AÀFÈaÁK×CUÑCUÓCW×C_ÑC_Ð`bÓCcÔdØ'0×'7Ñ'7Ô'9Ó:Ñ'9˜e˜”	Ñ'9Ñ:Ð:ùÒ:s   ÂB%c               ó$   € V ^8„  d   QhRRRRRR/# )r   rV   r@   rK   r   r"   r$   )r%   s   "r&   r'   r(   ö   s&   € ÷ ^ñ ^ <ð ^¸Sð ^À\ñ ^r)   c                	óx  € VR,          pVR,          VR,          ,          VR,          VR,          ,          ,
          P                  4       P                  4       pVR,          P                  V P                  4      P	                  4       P                  4       P                  ^ V^,
          4      P                  4       # ).g      #@rd   ).re   re   ).r…   r…   ).re   r…   ).r…   re   )ÚabsÚsqrtr¦   r6   Úlog2r�   ÚclamprŽ   )r9   rV   rK   r�   Údets   &&&  r&   Ú_select_levelsÚ(SIFTDescriptorFromPyramid._select_levelsö   s�   € Ø�kÕ"ˆØ�iÕ  6¨)Õ#4Õ4°v¸iÕ7HÈ6ÐR[ÕK\Õ7\Õ\×aÑaÓc×hÑhÓjˆà�c•	×$Ñ$ T§X¡XÓ.×3Ñ3Ó5×;Ñ;Ó=×CÑCÀAÀzÐTUÅ~ÓV×[Ñ[Ó]Ð]r)   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   rV   r@   ÚpyramidrL   Úlevelr   r"   r$   )r%   s   "r&   r'   r(   ý   s*   € ÷ ñ ˜Lð Ð3Eð Ècð ÐVbñ r)   c           
     ó¼  € V^ 8X  d   V # V P                  4       p\        V4       F³  pW,          P                  RR w  rVW^,           ,          P                  RR w  rxVP                  \	        V4      V,          \	        V4      V,          .4      p	VR;;,          V	P                  ^^^^4      ,          uu&   VR,          R,           V	,          R,
          VR&   Kµ  	  V# )zIMap pixel-coordinate LAFs through ``pyrdown``'s align-corners-false grid.Nrc   rB   rd   ).ºNNNr   )ÚcloneÚrangerC   rm   r    rl   )
rV   r¶   r·   r    ÚindexÚsource_hÚsource_wÚtarget_hÚtarget_wÚscales
   &&&       r&   Ú_laf_at_levelÚ'SIFTDescriptorFromPyramid._laf_at_levelü   sÊ   € ð �AŒ:ØˆKð —‘“ˆÜ˜5–\ˆEØ!(¥×!5Ñ!5°b°cÐ!:ÑˆHØ!(°­Õ!3×!9Ñ!9¸"¸#Ð!>ÑˆHØ×%Ñ%¤u¨X£¸Õ'AÄ5ÈÃ?ÐU]ÕC]Ð&^Ó_ˆEØ�;× 5§:¡:¨a°°A°qÓ#9Õ9ÓØ!'¨	Õ!2°SÕ!8¸EÕ AÀCÕ GˆF�9Óñ "ð ˆr)   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )	r   r¶   rL   Ú	gradientsúlist[torch.Tensor | None]rV   r@   rG   r"   r$   )r%   s   "r&   r'   r(     sC   € ÷ 1Dñ 1Dà#ð1Dð -ð1Dð ð	1Dð
 ð1Dð 
ñ1Dr)   c           	     	ó
  € VP                   R ,          w  rVVP                  WVV P                  4      p\        \	        W4      4       EFv  w  pw  ršV
f   K  V P
                  P                  V4      P                  ^^R4      p\        V4       EF+  pWL,          V8H  P                  4       P                  4       pVP                  4       ^ 8X  d   KB  W<V^,           1V3,          pV P                  WáV4      pV P                  W¬V^,            WœV^,            V^4      p\        P                  ! RVR	,          VP                  VP                   4      4      p\#        VR
,          VR,          V P$                  4      w  ppVR\&        P(                  ,          ,          V P                  ,          R\&        P(                  ,          ,          pVP+                  4       P-                  4       V P                  ,          pVVP+                  4       ,
          pVV,          pVP                  ^VP                  4       V P                  4      pVP/                  RVVRV,
          ,          4       VP/                  RV^,           V P                  ,          VV,          4       V^ ,          P                  VP                   4      W|V3&   EK.  	  EKy  	  \0        P2                  ! \0        P4                  ! VP                  WV,          ^R4      RRR7      V P6                  P                  V4      4      pVP9                  ^4      pVP;                  ^R7      pVP=                  ^V^,
          V P                  ,          P?                  R4      4      P9                  R4      pVP=                  ^VP?                  R4      4      P9                  R4      pVP=                  ^V^,           V P                  ,          P?                  R4      4      P9                  R4      pVV,           RV,          ,
          p\        P@                  ! V^ 8g  V\        PB                  ! V4      4      p\        P@                  ! V^ 8g  RVV,
          ,          V,          \        PD                  ! V4      4      pVP                  VP                   4      P                  WV4      VP                  WV4      ,           pR\&        P(                  ,          V,          \G        V P                  4      ,          # )rY   zbnji,bnjs->bnisrZ   r^   Úcircular)Úmodera   rc   rN   rd   ©r¹   r¹   re   ©r¹   r¹   r…   )r   r   )$rC   rf   r!   Ú	enumerateÚzipr,   rn   r7   r»   ÚnonzeroÚflattenÚnumelrÂ   r}   rg   rk   r]   r   r6   r†   r‡   r�   rŽ   r�   ÚFÚconv1dÚpadr.   ÚsqueezeÚargmaxÚgatherr�   ÚwhereÚ	ones_likeÚ
zeros_liker    ) r9   r¶   rÅ   rV   rG   rp   rq   ÚresultÚlevel_indexr?   Úgradr;   Úbatch_indexÚselectedÚcurrent_lafsÚ
level_lafsr|   ru   r™   Úangler›   rœ   rž   Ú	histogramÚsmoothedr¼   ÚleftÚcenterÚrightÚdenominatorÚsafe_denominatorÚoffsets    &&&&&                           r&   Ú_orientationÚ&SIFTDescriptorFromPyramid._orientation  sð  € ð �z‰z˜"�~‰ˆØ—‘  d×&;Ñ&;Ó<ˆÜ*3´C¸Ó4K×*LÑ&ˆK™˜%ØŠ|áØ×2Ñ2×5Ñ5°dÓ;×CÑCÀAÀqÈ"ÓMˆIÜ$ QŸx�Ø"Õ/°;Ñ>×GÑGÓI×QÑQÓS�Ø—>‘>Ó# qÔ(ÙØ#°+Àµ/Ð$AÀ8Ð$KÕL�Ø!×/Ñ/°À{ÓS�
ØŸ,™,Ø {°Q¥Ð7¸È[Ð[\Í_Ð9]Ð_iÐkmó�ô ŸšÐ%6¸
À;Õ8OÐQX×Q[ÑQ[Ð\f×\lÑ\lÓQmÓn�Ü#BÀ5ÈÅ>ÐSXÐY`ÕSaÐcg×ckÑckÓ#lÑ �	˜5Ø! S¬4¯7©7¥]Õ3°t×7LÑ7LÕLÐPSÔVZ×V]ÑV]ÕP]Õ^�Ø Ÿ™Ó(×-Ñ-Ó/°$×2GÑ2GÕG�Ø'¨(¯.©.Ó*:Õ:�Ø%¨	Õ1�	Ø%×/Ñ/°°8·>±>Ó3CÀT×EZÑEZÓ[�	Ø×&Ñ& r¨5°)¸sÀ\Õ?QÕ2RÔSØ×&Ñ& r¨E°A­I¸×9NÑ9NÕ+NÐPYÐ\hÕPhÔiØ09¸!µ·±ÀÇÁÓ0M� HÐ,Ô-ô+  (ñ +Mô6 —8’8Ü�EŠE�&—.‘. ¥¨¨2Ó.°¸ZÔHØ×&Ñ&×)Ñ)¨&Ó1ó
ˆð ×#Ñ# AÓ&ˆØ—‘ A�Ó&ˆØ�‰˜q E¨A¥I°×1FÑ1FÕ#F×"QÑ"QÐRTÓ"UÓV×^Ñ^Ð_aÓbˆØ—‘  E§O¡O°BÓ$7Ó8×@Ñ@ÀÓDˆØ—‘  U¨Q¥Y°$×2GÑ2GÕ$G×#RÑ#RÐSUÓ#VÓW×_Ñ_Ð`bÓcˆØ˜U•l S¨6¥\Õ1ˆÜ Ÿ;š; {°aÑ'7¸ÄeÇoÂoÐVaÓFbÓcÐÜ—’˜[¨AÑ-¨s°d¸UµlÕ/CÐFVÕ/VÔX]×XhÒXhÐitÓXuÓvˆØ—‘˜Ÿ™Ó$×,Ñ,¨QÓ2°V·^±^ÀAÓ5IÕIˆØ”T—W‘W�}˜uÕ$¤u¨T×-BÑ-BÓ'CÕCÐCr)   c               ó    € V ^8„  d   QhRRRR/# ©r   Úhistr@   r"   r$   )r%   s   "r&   r'   r(   @  s   € ÷ ñ  \ð °lñ r)   c           	     óê  € VP                   P                  R8X  di   \        P                  ! 4       '       gN   \        P                  P                  4       '       g*   V P                  ^,          ^ 8X  d   V P                  V4      # V P                  P                  VP                  VP                   R7      pV P                  ^,          pVRRW3^,           1R3,          pVRRRW3^,           13,          VRRW3^,           1W3^,           13,          ,          p\        P                  ! VP                  R^VP                  R	,          VP                  R,          4      V^ V3R7      p\        P                  ! WeV^ 3R7      P                  VP                  ^ ,          VP                  ^,          VP                  R	,          V P                  ^,          ^ 8H  ,           VP                  R,          V P                  ^,          ^ 8H  ,           4      pV P                  ^,          ^ 8X  dQ   RVRRRR1RR13,          VRRRRR13,          ,           VRRRR1R3,          ,           VR
,          ,           ,          pV# TpV# )zNPool spatial cells without allocating a two-dimensional convolution workspace.Úcpur„   r¹   )Úpaddingç      Ð?Nºr…   NNrN   rB   )r¹   r¹   ró   ró   )r\   Útyperg   Úis_grad_enabledÚcompilerÚis_compilingr   Ú_pool_histograms_cpu_inferencer+   rn   r]   rÑ   Úconv2dr7   rC   )r9   rî   Úkernelrå   Ú
horizontalÚverticalÚpooleds   &&     r&   Ú_pool_histogramsÚ*SIFTDescriptorFromPyramid._pool_histograms@  s  € ð �K‰K×Ñ Ô%Ü×)Ò)×+Ò+Ü—N‘N×/Ñ/×1Ò1Ø×%Ñ%¨Õ)¨QÔ.à×6Ñ6°tÓ<Ð<Ø×/Ñ/×2Ñ2¸¿¹ÈDÏKÉKÐ2ÓXˆð ×&Ñ&¨!Õ+ˆØ˜A˜q &°A­:Ð"5°qÐ8Õ9ˆ
Ø˜!˜Q  6°Q­JÐ#6Ð6Õ7¸&ÀÀAÀvÐYZÕPZÐGZÐ\bÐnoÕeoÐ\oÐAoÕ:pÕpˆÜ—’˜$Ÿ,™, r¨1¨d¯j©j¸­n¸d¿j¹jÈ½nÓMÈzÐdeÐgmÐcnÔoˆÜ—’˜&°V¸Q°KÔ@×HÑHØ�J‰J�q�MØ�J‰J�q�MØ�J‰J�r�N˜d×3Ñ3°aÕ7¸1Ñ<Õ=Ø�J‰J�r�N˜d×3Ñ3°aÕ7¸1Ñ<Õ=ó	
ˆð × Ñ  1Õ$¨Ô)ð Ø�q˜!˜S˜b˜S # 2 #�~Õ&¨°°1°b¸#¸2¸#°Õ)>Õ>ÀÈÈ1ÈcÈrÈcÐSUÈÕAVÕVÐY_Ð`lÕYmÕmõˆDð
 ˆð ˆDØˆr)   c               ó    € V ^8„  d   QhRRRR/# rí   r$   )r%   s   "r&   r'   r(   a  s   € ÷ &ñ &°<ð &ÀLñ &r)   c           
     ó  € V P                   pV^,          pV P                  P                  V4      ^ ^ V3,          pVP                  RR w  rV\        P
                  ! WV^ ^ 34      pVP                  ! . VP                  RR	 OV^,           N5!  pVP                  4       p	^ p
\        ^ WZ4       FŸ  p\        Wº,           V4      pVRW¼1R3,          p\        P                  ! VRW¼1RV^,           13,          V	^ ,          VR7       \        V	R,          ^4       F2  w  rïVP                  VRW¼1WîV,           ^,           13,          VR7       K4  	  K¡  	  \        P
                  ! V^ ^ W334      pWC,          pVV,          P                  4       p	VP                  ! VP                  !  p\        ^ WZ4       EFP  p\        Wº,           V4      pVP                  ! . VP                  RR OWË,
          ^,           NV^,           N5!  p\        P                  ! VRW¼^,           1R3,          V	^ ,          VR7       \        V	R,          ^4       F7  w  rïVP                  VRW¾,           WÎ,           ^,           1R3,          VR7       K9  	  VRW¼1R3,          p\        P                  ! VRRR	1RR	13,          VRRRR	13,          VR7       VP                  VRRR	1R3,          4      P                  VR
,          4      P                  R4       EKS  	  V# )zéCPU inference tent pooling with reusable accumulation maps.

The differentiable convolution path above remains the fallback.  ``add_``
with a scalar coefficient avoids allocating a product and sum map for
every separable-kernel tap.
N.r¹   )Úoutró   )Úalpharò   rB   rN   ).ró   ró   )r   r+   rn   rC   rÑ   rÓ   Ú	new_emptyr§   r»   rD   rg   ÚmulrÌ   Úadd_ÚaddÚmul_)r9   rî   Úsizerå   ÚweightrE   rF   Úpaddedrû   ÚweightsÚ	tile_rowsÚ	row_startÚrow_endr    r¼   ÚvalueÚ
normalizerrü   Ú
registereds   &&                 r&   rø   Ú8SIFTDescriptorFromPyramid._pool_histograms_cpu_inferencea  sÆ  € ð ×$Ñ$ˆØ˜•ˆØ×/Ñ/×2Ñ2°4Ó8¸¸A¸v¸ÕFˆØŸ
™
 2 3˜‰ˆÜ—’�t f¨a°Ð3Ó4ˆØ—^’^Ð@ T§Z¡Z°° _Ð@°e¸aµiÓ@ˆ
ð —-‘-“/ˆØˆ	Ü˜q &Ö4ˆIÜ˜)Õ/°Ó8ˆGØ  YÐ%6¸Ð 9Õ:ˆFÜ�IŠI�f˜S )Ð"3°[°u¸qµy°[Ð@ÕAÀ7È1Å:ÐSYÕZÜ )¨'°"­+°qÖ 9‘�Ø—‘˜F 3¨	Ð(9¸5È5Å=ÐSTÕCTÐ;TÐ#TÕUÐ]b�Öcó !:ñ	 5ô —’�z A q¨&Ð#9Ó:ˆØ•^ˆ
Ø˜JÕ&×.Ñ.Ó0ˆØ—’ §¡Ñ,ˆÜ˜q &×4ˆIÜ˜)Õ/°Ó8ˆGð —~’~Ð[ t§z¡z°#°2 Ð[¸Õ8KÈaÕ8OÐ[ÐQVÐYZÕQZÓ[ˆHÜ�IŠI�f˜S )¸­kÐ"9¸1Ð<Õ=¸wÀq½zÈxÕXÜ )¨'°"­+°qÖ 9‘�Ø—‘˜f S¨)Õ*;¸g½oÐPQÕ>QÐ*QÐSTÐ%TÕUÐ]b�Öcñ !:à  YÐ%6¸Ð 9Õ:ˆJÜ�IŠI�h˜s C R C¨¨"¨˜}Õ-¨x¸¸RÀÀ"À¸Õ/EÈ:ÕVØ�O‰O˜H S¨#¨2¨#¨r \Õ2Ó3×8Ñ8¸À+Õ9NÓO×TÑTÐUY×Zñ 5ð ˆr)   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )	r   r¶   rL   r€   rÆ   rV   r@   rG   r"   r$   )r%   s   "r&   r'   r(   ‰  s<   € ÷ "ñ "à#ð"ð .ð"ð ð	"ð
 ð"ð 
ñ"r)   c           	     	ó(  € VP                   R ,          w  rVVP                  WVV P                  V P                  V P                  ,          4      p\	        \        W4      4       EF  w  pw  ršV
f   K  V P                  V
4      p
\        V4       Fß  pWK,          V8H  P                  4       P                  4       pVP                  4       ^ 8X  d   KA  W;V^,           1V3,          pV P                  WÑV4      pV P                  W«V^,            W›V^,            VV P                  4      pV P                  WþR,          V P                  4      pV^ ,          P                  VP                  4      W{V3&   Ká  	  EK  	  VP                  ^4      p\!        VRR7      P#                  RV P$                  4      p\!        VRR7      pV P&                  '       dG   \)        VP+                  RVP                   R,          4      V P,                  4      P/                  V4      # V# )rY   ra   ç        rd   rN   )rC   rf   r   r   rÌ   rÍ   rþ   r»   rÎ   rÏ   rÐ   rÂ   r}   r¡   rn   r]   r   r±   r   r   r   r7   r6   Ú
reshape_as)r9   r¶   r€   rV   rG   rp   rq   rÚ   rÛ   r?   rî   rÝ   rÞ   rß   rà   r|   ÚmappedÚdescs   &&&&&             r&   Ú_descriptorsÚ&SIFTDescriptorFromPyramid._descriptors‰  sÀ  € ð �z‰z˜"�~‰ˆØ—‘  d×&7Ñ&7¸×9NÑ9NÐQU×QfÑQfÕ9fÓgˆÜ*3´C¸Ó4L×*MÑ&ˆK™˜%ØŠ|ñ Ø×(Ñ(¨Ó.ˆDÜ$ Qžx�Ø"Õ/°;Ñ>×GÑGÓI×QÑQÓS�Ø—>‘>Ó# qÔ(ÙØ#°+Àµ/Ð$AÀ8Ð$KÕL�Ø!×/Ñ/°À{ÓS�
ØŸ,™,Ø {°Q¥Ð7Ø¨°a­Ð8ØØ×)Ñ)ó	�ð ×+Ñ+¨GÀÕ5LÈd×N_ÑN_Ó`�Ø06°qµ	·±¸V¿\¹\Ó0J� HÐ,Ó-ô  (ñ +Nð( �~‰~˜aÓ ˆÜ˜T rÔ*×0Ñ0°°d·l±lÓCˆÜ˜T rÔ*ˆØ�=�=ˆ=Ü˜TŸ\™\¨"¨d¯j©j¸­nÓ=¸t¿x¹xÓH×SÑSÐTXÓYÐYØˆr)   c               ó$   € V ^8„  d   QhRRRRRR/# )r   r?   r@   rV   r"   r$   )r%   s   "r&   r'   r(   ­  s&   € ÷ Fñ F˜\ð F°ð FÀ,ñ Fr)   c                ó6   € V P                  WRR7      ^,          # )a‹  Describe supplied oriented frames without detecting or reorienting them.

Args:
    image: Grayscale floating-point image of shape ``(B, 1, H, W)``.
    lafs: Already oriented pixel-coordinate frames of shape ``(B, N, 2, 3)``.

Returns:
    Sparse descriptors of shape ``(B, N, num_ang_bins * num_spatial_bins**2)``,
    with the image dtype and device. Invalid frames receive zero descriptors.
T)Úupright)Úorient_and_describe)r9   r?   rV   s   &&&r&   ÚforwardÚ!SIFTDescriptorFromPyramid.forward­  s   € ð ×'Ñ'¨¸TÐ'ÓBÀ1ÕEÐEr)   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r   r?   r@   rV   r  r   r"   z!Tuple[torch.Tensor, torch.Tensor]r$   )r%   s   "r&   r'   r(   º  s8   € ÷ XHñ XHØ!ðXHØ)5ðXHØ@DðXHà	*ñXHr)   c           	     óž
  € \        V. RO4       \        V4       VP                  ^ ,          VP                  ^ ,          8w  d4   \        RVP                  ^ ,           RVP                  ^ ,           24      hVP                  VP                  rTVP                  VP                  R7      pVP                  ^ ,          ^ 8X  g   VP                  ^,          ^ 8X  d¤   VR,          P                  4       VR,          P                  4       ,           pVP                  VP                  ^ ,          VP                  ^,          V P                  V P                  ^,          ,          4      V,           pW'P                  V4      3# \        VP                  VP                  4      pVP                  V4      pVP                  \        P                  \        P                  39   d   VP                  4       p\!        V4      p	\        P"                  ! ^^VP                  VP                  R7      P%                  ^^^^4      p
\        P&                  ! V	P$                  ! . V	P                  O^N^N5!  W*4      pV P)                  V4      pV P+                  W¼4      P-                  V	( R4      pV P/                  WÜ4      p\1        R \3        V4       4       RR7      pV^ 8  d´   VR,          P                  4       VR,          P                  4       ,           pVP                  VP                  ^ ,          VP                  ^,          V P                  V P                  ^,          ,          4      V,           pVP                  V4      VP                  V4      3# V P5                  W^,           4      p. p. p\3        V4       F¿  w  ppVV,          '       g%   VP7                  R4       VP7                  R4       K9  \9        VR4      pVP7                  \;        VR,          VR,          V P<                  V P>                  4      4       V'       d   KŽ  \A        VRRR	R
7      pVP7                  \9        VR4      R,          4       KÁ  	  V'       d   TpMCV PC                  VVW½4      p\E        V\        PF                  ! V4      PI                  R4      ) 4      pV PK                  VVVV4      p\        P&                  ! V	P$                  ! . V	P                  O^N^N5!  VV4      pVP-                  V	PI                  R4      ( R4      pVP                  V4      VP                  V4      3# )aû  Orient and describe sparse frames, building the extraction pyramid once.

Args:
    image: Grayscale floating-point image of shape ``(B, 1, H, W)``.
    lafs: Pixel-coordinate frames of shape ``(B, N, 2, 3)``.
    upright: Preserve the supplied frame orientations rather than estimating them.

Returns:
    Oriented frames in the input LAF dtype and descriptors in the image
    dtype, both on the image device. Invalid frames are preserved and
    receive zero descriptors. Empty frame sets are supported.
z2image and lafs must have the same batch size. Got z and )r\   r[   c              3  ó>   "  € T F  w  rV'       g   K  Vx € K  	  R # 5i©Nr$   )Ú.0r¼   Úuseds   &  r&   Ú	<genexpr>Ú@SIFTDescriptorFromPyramid.orient_and_describe.<locals>.<genexpr>è  s   é € ÐPÑ2G¡; 5Ì4ŸšÓ2Gùs   ‚“
)ÚdefaultNÚdiffÚ	replicate)Úborder_typer  )ÚBÚ1ÚHÚW).ºNre   Nr2  ).r2  rN   rÊ   rË   )é   r3  )r^   r^   )r¹   re   )&r   r   rC   r3   r]   rn   r\   Úsumrf   r   r   r	   rg   Úfloat16Úbfloat16r    r
   Úeyerl   r×   rH   r³   Úmasked_fillrª   r4   rÌ   rQ   rP   r   r   r5   r6   r   rê   r   Úrad2degr�   r  )r9   r?   rV   r  Úimage_dtypeÚ	laf_dtypeÚzeroÚdescriptorsr•   ÚvalidÚidentityÚ	safe_lafsrK   rG   Ú
level_usedÚ	max_levelr¶   r€   Úorientation_gradientsrÛ   rU   rÅ   rã   Úoriented_lafsr–   s   &&&&                     r&   r  Ú-SIFTDescriptorFromPyramid.orient_and_describeº  sY  € ô 	˜5Ò"6Ô7Ü˜ÔØ�;‰;�q�>˜TŸZ™Z¨�]Ô*ÜÐQÐRW×R]ÑR]Ð^_ÕR`ÐQaÐafÐgk×gqÑgqÐrsÕgtÐfuÐvÓwÐwØ!&§¡¨d¯j©j�YØ�w‰w˜eŸl™lˆwÓ+ˆØ�;‰;�q�>˜QÔ $§*¡*¨Q¥-°1Ô"4ð ˜Õ%×)Ñ)Ó+¨d°7­m×.?Ñ.?Ó.AÕAˆDà—‘ §¡¨A¥°·
±
¸1µ¸t×?PÑ?PÐSW×ShÑShÐjkÕSkÕ?kÓlÐosÕsð ð Ÿ™¨Ó4Ð4Ð4ô -¨U¯[©[¸$¿*¹*ÓEˆØ�w‰w�}Ó%ˆØ�;‰;œ5Ÿ=™=¬%¯.©.Ð9Ô9Ø—K‘K“MˆEÜ˜TÓ"ˆÜ—9’9˜Q ¨$¯+©+¸T¿Z¹ZÔH×MÑMÈaÐQRÐTUÐWXÓYˆô —K’K §
¢
Ð >¨E¯K©KÐ >¸Ð >¸AÓ >ÀÓOˆ	Ø×-Ñ-¨eÓ4ˆ
Ø×$Ñ$ YÓ;×GÑGÈÈÐPRÓSˆð ×*Ñ*¨6Ó>ˆ
ÜÑP´)¸JÔ2GÓPÐZ\Ô]ˆ	Ø�qŒ=ð ˜Õ%×)Ñ)Ó+¨i¸Õ.@×.DÑ.DÓ.FÕFˆDà—‘ §¡¨A¥°·
±
¸1µ¸t×?PÑ?PÐSW×ShÑShÐjkÕSkÕ?kÓlÐosÕsð ð —7‘7˜9Ó% {§~¡~°kÓ'BÐBÐBØ—-‘- °1¥}Ó5ˆØ02ˆ
Ø;=ÐÜ(1°'Ö(:Ñ$ˆK˜ð
 ˜k×*Ô*Ø×!Ñ! $Ô'Ø%×,Ñ,¨TÔ2ÙÜ3°KÀÓHˆIØ×ÑÜ5Ø˜gÕ&¨	°'Õ(:¸D×<QÑ<QÐSW×S[ÑS[óô÷
 ‘7ô +¨;¸À
ÐXcÔd�Ø%×,Ñ,Ô-HÈÐSYÓ-ZÐ[_Õ-`Öañ' );÷( Ø%‰Mà×&Ñ& wÐ0EÀyÓYˆFô ' y´5·=²=ÀÓ3H×3RÑ3RÐSUÓ3VÐ2VÓWˆMØ×'Ñ'¨°¸]ÈFÓSˆÜŸš E§J¢JÐ$B°·±Ð$B¸QÐ$BÀÓ$BÀMÐSWÓXˆØ!×-Ñ-¨u¯©¸rÓ/BÐ.BÀCÓHˆØ×Ñ 	Ó*¨K¯N©N¸;Ó,GÐGÐGr)   )r5   r   r6   r   r   r!   r   r   )é   é   rF  Tgš™™™™™É?é$   r%  )F)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r2   ÚstaticmethodrH   rQ   r}   r¡   rª   r³   rÂ   rê   rþ   rø   r  r   r  Ú__static_attributes__Ú__classcell__)r<   s   @r&   r   r   0   s³   ø† ñ[÷z
ò 
ð@ ôó ð÷ð ôaó ðað" ô'ó ð'ð2 ô;ó ð;õ^ð ôó ðõ 1DõfõB&õP"õHF÷XHõ XHr)   r   )#rM  Ú
__future__r   r†   Útypingr   rg   Útorch.nn.functionalr   Ú
functionalrÑ   Úkornia.core.checkr   r   Úkornia.core.utilsr   Úkornia.feature.lafr   r	   r
   r   Úkornia.feature.siftdescr   r   r   r   r   Úkornia.filtersr   r   r   Úkornia.geometry.transformr   ÚModuler   r$   r)   r&   Ú<module>r\     sZ   ðñ$ Cå "ã Ý ã ß Ð Ý ç BÝ +÷ó ÷õ ÷ bÑ aÝ -ôbH §	¡	ö bHr)   