+
    åûj!  ã                   óÊ   € ^ RI t ^ RIHt ^ RItR R ltRR R lltR R ltR	 R
 ltRR R lltR R lt	R R lt
R R ltRR/R R lltRR/R R lltR R ltR R ltR# )é    N)ÚTuplec                óX   € V ^8„  d   QhR\         P                  R\         P                  /# )é   ÚrangesÚreturn©ÚtorchÚTensor)Úformats   "ÚWC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\feature\adalam\utils.pyÚ__annotate__r      s&   € ÷ Cñ CœEŸL™Lð C¬U¯\©\ñ Có    c                ó$  € \         P                  ! V 4      P                  4       pV P                  ^ ,          p\         P                  ! WP
                  R7      P                  ^ 4      P                  VR4      pW3V P                  R4      8  ,          # )zuReturn a sequence of the ranges specified by the argument.

Example:
[2, 5, 1, 2] -> [0, 1, 0, 1, 2, 3, 4, 0, 0, 1]

)Údeviceéÿÿÿÿ)r	   ÚmaxÚitemÚshapeÚaranger   Ú	unsqueezeÚexpand)r   ÚmaxcntÚnumuniÚcomplete_rangess   &   r   Úarange_sequencer      sm   € ô �YŠY�vÓ×#Ñ#Ó%€FØ�\‰\˜!�_€FÜ—l’l 6·-±-Ô@×JÑJÈ1ÓM×TÑTÐU[Ð]_Ó`€Oà¨V×-=Ñ-=¸bÓ-AÑAÕBÐBr   c                ó„   € V ^8„  d   QhR\         P                  R\         P                  R\        R\         P                  /# )r   Úd1Úd2Úis_normalizedr   ©r	   r
   Úbool)r   s   "r   r   r   &   s7   € ÷ /ñ /”E—L‘Lð /¤e§l¡lð /Ä4ð /ÔTY×T`ÑT`ñ /r   c                óR  € V'       d&   ^RV ,          VP                  4       ,          ,
          # V ^,          P                  ^4      P                  R^4      pV^,          P                  ^4      P                  ^R4      pW4,           RV ,          VP                  4       ,          ,
          # )zDistance between two tensors.ç       @r   )ÚtÚsumÚview)r   r   r   Úx_normÚy_norms   &&&  r   Údist_matrixr)   &   sw   € çØ�3˜•8˜bŸd™d›fÕ$Õ$Ð$Ø�!�e�[‰[˜‹^× Ñ   QÓ'€FØ�!�e�[‰[˜‹^× Ñ   BÓ'€Fà�?˜S 2�X¨¯©«Õ.Õ.Ð.r   c                óx   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  /# )r   Úo1Úo2r   r   )r   s   "r   r   r   1   s-   € ÷ 6ñ 6œŸ™ð 6¬5¯<©<ð 6¼E¿L¹Lñ 6r   c                óš   € W,
          p\         P                  ! VR8  VR,           V4      p\         P                  ! V^´8¬  VR,
          V4      # )z+Orientation difference between two tensors.ih  iLÿÿÿ)r	   Úwhere)r+   r,   Údiffs   && r   Úorientation_diffr0   1   s>   € à�7€DÜ�;Š;�t˜d‘{ D¨3¥J°Ó5€DÜ�;Š;�t˜s‘{ D¨3¥J°Ó5Ð5r   c                óX   € V ^8„  d   QhR\         P                  R\         P                  /# )r   Úpiecewise_idxerr   r   )r   s   "r   r   r   8   s"   € ÷ #ñ #¤e§l¡lð #´u·|±|ñ #r   c                óL   € \         P                  ! V RR7      w  r\        V4      # )zcCount repeated indices.

Example:
[0, 0, 0, 3, 3, 3, 3, 1, 1, 2] -> [0, 1, 2, 0, 1, 2, 3, 0, 1, 0]
T)Úreturn_counts)r	   Úunique_consecutiver   )r2   Ú_Úcountss   &  r   Úpiecewise_aranger8   8   s#   € ô ×(Ò(¨ÈÔM�I€AÜ˜6Ó"Ð"r   c                ód   € V ^8„  d   QhR\         P                  R\        R\         P                  /# )r   ÚmÚ
check_detsr   r    )r   s   "r   r   r   B   s)   € ÷ 2ñ 2”U—\‘\ð 2¬tð 2ÄÇÁñ 2r   c                ó\  € V R,          pV R,          pV R,          pV R,          p\         P                  ! V 4      pW%,          W4,          ,
          pV'       d   RV\         P                  ! V4      R8  &   WVR&   W&R&   V) VR&   V) VR&   WgP                  R4      P                  R4      ,          # )z(Return inverse of batch of 2x2 matrices.g»½×Ùß|Û=©.r   r   ©.r   é   ©.r?   r   ©.r?   r?   r   )r	   Ú
empty_likeÚabsr   )r:   r;   ÚaÚbÚcÚdÚminvÚdets   &&      r   Úbatch_2x2_invrJ   B   sž   € à	ˆ)�€AØ	ˆ)�€AØ	ˆ)�€AØ	ˆ)�€AÜ×Ò˜AÓ€DØ
�%�!•%�-€CßØ&+ˆŒE�IŠI�c‹N˜UÑ"Ñ#Øˆ�OØˆ�OØ�b€Dˆ�OØ�b€Dˆ�OØ—-‘- Ó#×-Ñ-¨bÓ1Õ1Ð1r   c                óX   € V ^8„  d   QhR\         P                  R\         P                  /# ©r   r:   r   r   )r   s   "r   r   r   S   s"   € ÷ =ñ =”5—<‘<ð =¤E§L¡Lñ =r   c                ó.   € \        \        V 4      RR7      # )z"Return Q of batch of 2x2 matrices.T)r;   )rJ   Úbatch_2x2_invQ©r:   s   &r   Úbatch_2x2_QrP   S   s   € äœ¨Ó*°tÔ<Ð<r   c                óX   € V ^8„  d   QhR\         P                  R\         P                  /# rL   r   )r   s   "r   r   r   X   s"   € ÷ #ñ #”e—l‘lð #¤u§|¡|ñ #r   c                ó2   € W P                  RR4      ,          # )z*Return inverse Q of batch of 2x2 matrices.r   éþÿÿÿ)Ú	transposerO   s   &r   rN   rN   X   s   € à�{‰{˜2˜rÓ"Õ"Ð"r   c                óX   € V ^8„  d   QhR\         P                  R\         P                  /# rL   r   )r   s   "r   r   r   ]   s"   € ÷ ñ ”U—\‘\ð ¤e§l¡lñ r   c                ót   € V R,          pV R,          pV R,          pV R,          pW,          W#,          ,
          # )z,Return determinant of batch of 2x2 matrices.r=   r>   r@   rA   © )r:   rD   rE   rF   rG   s   &    r   Úbatch_2x2_detrX   ]   s4   € à	ˆ)�€AØ	ˆ)�€AØ	ˆ)�€AØ	ˆ)�€AØ�5�1•5�=Ðr   Úepsç        c                ód   € V ^8„  d   QhR\         P                  R\        R\         P                  /# ©r   r:   rY   r   )r	   r
   Úfloat)r   s   "r   r   r   f   s)   € ÷ )ñ )œ5Ÿ<™<ð )´ð )ÄÇÁñ )r   c               óØ  € V R,          pV R,          pV R,          pV R,          pW",          W3,          ,           pW$,          W5,          ,           pWD,          WU,          ,           pRWh,           ,          p	RWh,
          ,          p
\         P                  ! W§4      pV^ 8”  d   TMRpW›,           P                  VR7      pW›,
          P                  VR7      p\         P                  ! WÞ.R	R7      # )
z?Return eigenvalues of ``m @ m.mT`` for a batch of 2x2 matrices.ç      à?rZ   )Úmin©Údimr=   r>   r@   rA   r   )r	   ÚhypotÚclampÚstack)r:   rY   ÚamÚbmÚcmÚdmrD   rE   rG   Útrhr/   ÚsqrtdiscÚmin_valÚe1Úe2s   &$             r   Úbatch_2x2_eigenvalsro   f   sÀ   € à	
ˆ9�€BØ	
ˆ9�€BØ	
ˆ9�€BØ	
ˆ9�€Bà
��"•'Õ€AØ
��"•'Õ€AØ
��"•'Õ€Aà
�•�-€CØ�!•%�=€Dô �{Š{˜4Ó#€Hà˜1”W‰c #€GØ
�.×	Ñ	 GÐ	Ó	,€BØ
�.×	Ñ	 GÐ	Ó	,€BÜ�;Š;˜�x RÔ(Ð(r   c                óš   € V ^8„  d   QhR\         P                  R\        R\        \         P                  \         P                  3,          /# r\   )r	   r
   r]   r   )r   s   "r   r   r   }   s:   € ÷  ñ  œŸ™ð  ¬uð  ¼uÄUÇ\Á\ÔSX×S_ÑS_ÐE_Õ?`ñ  r   c               ó.  € \        WR7      pV R,          pV R,          pV R,          pV R,          pW3,          WD,          ,           pW5,          WF,          ,           pWU,          Wf,          ,           p	R\        P                  ! RV,          Wy,
          4      ,          p
\        P                  ! V
4      p\        P                  ! V
4      p\        P
                  ! W¼.R	R7      p\        P
                  ! V) V.R	R7      p\        P
                  ! WÞ.R	R7      pW/3# )
z=Return Eigenvalues and Eigenvectors of batch of 2x2 matrices.)rY   r_   r#   ra   r=   r>   r@   rA   r   )ro   r	   Úatan2ÚcosÚsinre   )r:   rY   Ú	eigenvalsrf   rg   rh   ri   rD   rE   rG   ÚthetarF   ÚsÚev1Úev2Ú	eigenvecss   &$              r   Úbatch_2x2_ellipser{   }   sÔ   € ä# AÔ/€IØ	
ˆ9�€BØ	
ˆ9�€BØ	
ˆ9�€BØ	
ˆ9�€Bà
��"•'Õ€AØ
��"•'Õ€AØ
��"•'Õ€Aà”%—+’+˜c A�g q¥uÓ-Õ-€EÜ�	Š	�%Ó€AÜ�	Š	�%Ó€Aä
�+Š+�q�f "Ô
%€CÜ
�+Š+˜�r˜1�g 2Ô
&€CÜ—’˜S˜J¨BÔ/€IØÐÐr   c                ó„   € V ^8„  d   QhR\         R\        P                  R\        P                  R\        P                  /# )r   ÚkÚrdimsÚdvr   ©Úintr	   r
   r   )r   s   "r   r   r   “   s4   € ÷ >ñ >œCð >¬¯©ð >¼%¿,¹,ð >Ì5Ï<É<ñ >r   c                ó,  € \        \        P                  ! ^V ,          R,           4      R,
          4      pV^,           p\        P                  ! WDRVR7      RRV 13,          P                  4       p\        P                  ! VP                  R4      V4      # )aw  Return first k couples.

Exhaustive search over the first n samples:
 * n(n+1)/2 = n2/2 + n/2 couples
Max n for which we can exhaustively sample with k couples:
* n2/2 + n/2 = k
* n = sqrt(1/4 + 2k)-1/2 = (sqrt(8k+1)-1)/2

The couples are ``(1, 0), (2, 0), (2, 1), (3, 0), ...``: the ``k`` distinct pairs ``(i, j)`` with ``j < i`` in
that order, so the residual couples after the complete rows continue with ``(n + 1, 0), (n + 1, 1), ...``. The
reference AdaLAM implementation used the residual count as that first index, which repeated couples already
drawn (8 of the default 128) instead of trying new ones. Each region then takes the indices modulo its number of
samples in ``rdims``, so the couples stay distinct only in a region with enough samples for ``k`` distinct
couples, at least 17 for ``k = 128``; in a smaller region they wrap, and can repeat or pair a sample with itself.
g      Ð?r_   )Úoffsetr   :NNNNr   )r�   ÚmathÚsqrtr	   Útril_indicesr$   Ú	remainderr   )r}   r~   r   Úmax_exhaustive_searchÚsizeÚidx_sequences   &&&   r   Údraw_first_k_couplesr‹   “   sw   € ô   ¤§	¢	¨!¨a­%°$­,Ó 7¸#Õ =Ó>Ðð ! 1Õ$€DÜ×%Ò% d¸ÀBÔGÈÈ2ÈAÈ2ÈÕN×PÑPÓR€LÜ�?Š?˜<×1Ñ1°"Ó5°uÓ=Ð=r   c                ó„   € V ^8„  d   QhR\         R\        P                  R\        P                  R\        P                  /# )r   Úitersr~   r   r   r€   )r   s   "r   r   r   «   s7   € ÷ ñ ¤#ð ¬e¯l©lð ÄÇÁð ÔQV×Q]ÑQ]ñ r   c                ó´   € \         P                  ! V ^VP                  ^ ,          3VR7      pW1R,
          P                  4       ,          pVP	                  4       # )z(Randomly sample indices of torch.Tensor.)r‰   r   g:Œ0âŽyE>)r	   Úrandr   r]   Úlong)r�   r~   r   ÚrandsÚscaled_randss   &&&  r   Úrandom_samples_indicesr“   «   sE   € ä�JŠJ˜U A u§{¡{°1¥~Ð6¸rÔB€EØ D�L×/Ñ/Ó1Õ1€LØ×ÑÓÐr   )F)r„   Útypingr   r	   r   r)   r0   r8   rJ   rP   rN   rX   ro   r{   r‹   r“   rW   r   r   Ú<module>r•      s[   ðó$ Ý ã õC÷/õ6õ#÷2õ"=õ
#õ
ð)¸÷ )ð. °s÷  õ,>÷0r   