+
    åûj  ã                   óX   € ^ RI t ^ RIHt ^ RIt^ RIHt  ! R R]P
                  4      tR# )é    N)ÚTuple)Únnc                   óˆ   a a€ ] tR t^t oRtRV3R lV 3R llltV3R lR ltV3R lR ltV3R lR	 ltV3R
 lt	Rt
VtV ;t# )ÚPositionEncodingSinezHA sinusoidal position encoding that generalized to 2-dimensional images.c                óF   <€ V ^8„  d   QhRS[ RS[S[ S[ 3,          RS[RR/# )é   Úd_modelÚ	max_shapeÚtemp_bug_fixÚreturnN)Úintr   Úbool)ÚformatÚ__classdict__s   "€ÚhC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\feature\loftr\utils\position_encoding.pyÚ__annotate__Ú!PositionEncodingSine.__annotate__   s3   ø€ ÷ 9ñ 9¡ð 9±±c¹3°hµð 9Ñ\`ð 9Ðlpñ 9ó    c                ó†   <€ \         SV `  4        Wn        W0n        V P	                  V4      pV P                  RVRR7       R# )a  Construct sinusoidal positional encoding.

Args:
d_model: Dimensions of model input.
max_shape (tuple): for 1/8 featmap, the max length of 256 corresponds to 2048 pixels
temp_bug_fix (bool): As noted in this [issue](https://github.com/zju3dv/LoFTR/issues/41),
    the original implementation of LoFTR includes a bug in the pos-enc impl, which has little impact
    on the final performance. For now, we keep both impls for backward compatibility.
    We will remove the buggy impl after re-training all variants of our released models.

ÚpeF)Ú
persistentN)ÚsuperÚ__init__r	   r   Ú_create_position_encodingÚregister_buffer)Úselfr	   r
   r   r   Ú	__class__s   &&&& €r   r   ÚPositionEncodingSine.__init__   s@   ø€ ô 	‰ÑÔØŒØ(Ôà×+Ñ+¨IÓ6ˆØ×Ñ˜T 2°%ÐÖ8r   c                óP   <€ V ^8„  d   QhRS[ S[S[3,          RS[P                  /# )r   r
   r   )r   r   ÚtorchÚTensor)r   r   s   "€r   r   r   1   s'   ø€ ÷ ñ ±5¹¹c¸µ?ð ÁuÇ|Á|ñ r   c                ó   € \         P                  ! V P                  .VO54      p\         P                  ! V4      P	                  ^ 4      P                  4       P                  ^ 4      p\         P                  ! V4      P	                  ^4      P                  4       P                  ^ 4      pV P                  '       d�   \         P                  ! \         P                  ! ^ V P                  ^,          ^4      P                  4       \        P                  ! R4      ) V P                  ^,          ,          ,          4      pM\         P                  ! \         P                  ! ^ V P                  ^,          ^4      P                  4       \        P                  ! R4      ) V P                  ,          ^,          ,          4      pVR,          p\         P                  ! WE,          4      VR&   \         P                  ! WE,          4      VR&   \         P                  ! W5,          4      VR&   \         P                  ! W5,          4      VR&   VP                  ^ 4      # )z°Create a position encoding from scratch.

For 1/8 feature map (which is standard): If the input image size is H, W (both divisible by 8), the max_shape
should be (H//8, W//8).
g     ˆÃ@)ºNNNNN):r   Né   r#   r#   ):é   Nr$   r#   r#   ):r   Nr$   r#   r#   ):é   Nr$   r#   r#   )r    Úzerosr	   ÚonesÚcumsumÚfloatÚ	unsqueezer   ÚexpÚarangeÚmathÚlogÚsinÚcos)r   r
   r   Ú
y_positionÚ
x_positionÚdiv_terms   &&    r   r   Ú.PositionEncodingSine._create_position_encoding1   sš  € ô �[Š[˜$Ÿ,™,Ð3¨Ñ3Ó4ˆÜ—Z’Z 	Ó*×1Ñ1°!Ó4×:Ñ:Ó<×FÑFÀqÓIˆ
Ü—Z’Z 	Ó*×1Ñ1°!Ó4×:Ñ:Ó<×FÑFÀqÓIˆ
Ø××ÐÜ—y’yÜ—’˜Q §¡°Õ 1°1Ó5×;Ñ;Ó=Ä$Ç(Â(È7ÓBSÐASÐW[×WcÑWcÐghÕWhÕAiÕjó‰Hô —y’yÜ—’˜Q §¡°Õ 1°1Ó5×;Ñ;Ó=Ä$Ç(Â(È7ÓBSÐASÐVZ×VbÑVbÕAbÐfgÕAgÕhóˆHð ˜MÕ*ˆÜŸš :Õ#8Ó9ˆˆ:‰ÜŸš :Õ#8Ó9ˆˆ:‰ÜŸš :Õ#8Ó9ˆˆ:‰ÜŸš :Õ#8Ó9ˆˆ:‰Ø�|‰|˜A‹Ðr   c                ó:   <€ V ^8„  d   QhRS[ S[S[3,          RR/# )r   r
   r   N)r   r   )r   r   s   "€r   r   r   I   s'   ø€ ÷ kñ k±u¹SÁ#¸Xµð kÈ4ñ kr   c                ó¤   € V P                  V4      P                  V P                  P                  V P                  P                  R7      V n        R# )z²Update position encoding to new max_shape.

For 1/8 feature map (which is standard): If the input image size is H, W (both divisible by 8), the max_shape
should be (H//8, W//8).
)ÚdeviceÚdtypeN)r   Útor   r8   r9   )r   r
   s   &&r   Úupdate_position_encoding_sizeÚ2PositionEncodingSine.update_position_encoding_sizeI   s;   € ð ×0Ñ0°Ó;×>Ñ>ÀdÇgÁgÇnÁnÐ\`×\cÑ\c×\iÑ\iÐ>ÓjˆŽr   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# )r   Úxr   ©r    r!   )r   r   s   "€r   r   r   Q   s#   ø€ ÷ ;ñ ;™Ÿ™ð ;©%¯,©,ñ ;r   c           	     ó.  € VP                  ^4      V P                  P                  ^4      8”  g0   VP                  ^4      V P                  P                  ^4      8”  dz   \        VP                  ^4      V P                  P                  ^4      4      \        VP                  ^4      V P                  P                  ^4      4      3pV P                  V4       WP                  RRRVP                  ^4      1RVP                  ^4      13,          ,           # )z%Run forward.

Args:
x: [N, C, H, W]

r#   N)Úsizer   Úmaxr;   )r   r>   r
   s   && r   ÚforwardÚPositionEncodingSine.forwardQ   s½   € ð �6‰6�!‹9�t—w‘w—|‘| A“Ô&¨!¯&©&°«)°d·g±g·l±lÀ1³oÔ*EÜ˜QŸV™V A›Y¨¯©¯©°Q«Ó8¼#¸a¿f¹fÀQ»iÈÏÉÏÉÐVWËÓ:YÐZˆIØ×.Ñ.¨yÔ9à—7‘7˜1˜a  1§6¡6¨!£9 ¨k°·±°q³	¨kÐ9Õ:Õ:Ð:r   c                ó:   <€ V ^8„  d   Qh/ S[ P                  ;R&   # )r   r   r?   )r   r   s   "€r   r   r      s   ø‡ ‚ ñ 	�‰Ñò r   )r	   r   r   ))é   rF   T)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r;   rC   Ú__annotate_func__Ú__static_attributes__Ú__classdictcell__Ú__classcell__)r   r   s   @@r   r   r      s:   ù‡ € ÙR÷9õ 9÷&ð ÷0kð k÷;ð ;÷q … r   r   )r.   Útypingr   r    r   ÚModuler   © r   r   Ú<module>rS      s%   ðó$ Ý ã Ý ôC;˜2Ÿ9™9ö C;r   