ó
    Eñi  ã            
       ó”   • S SK Jr  S SKrS SKJs  Jr  S SKJr  SS\S\S\S\\	   4S jjr
SS	\S
\S\S\4S jjrSS\\   S\4S jjrg)é    )ÚOptionalN)ÚTensorÚimgÚabsolute_gridÚmodeÚalign_cornersc                 óæ   • U R                   SS u  pEUR                  SS/SS9u  pgSU-  US-
  -  S-
  nUS:”  a  SU-  US-
  -  S-
  n[        R                  " Xg/SS9n[        R
                  " XX#S9$ )z_Same as torch's grid_sample, with absolute pixel coordinates instead of normalized coordinates.éþÿÿÿNé   éÿÿÿÿ©Údimé   )r   r   )ÚshapeÚsplitÚtorchÚcatÚFÚgrid_sample)	r   r   r   r   ÚhÚwÚxgridÚygridÚnormalized_grids	            Úc/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torchvision/models/optical_flow/_utils.pyr   r      s†   € à�9‰9�R�Sˆ>�D€Aà ×&Ñ&¨¨1 v°2Ð&Ð6�L€EØ�‰I˜˜Q™Ñ !Ñ#€Eàˆ1ƒuØ�E‘	˜Q ™UÑ# aÑ'ˆÜ—i’i  °BÑ7€Oä�=Š=˜°DÑVÐVó    Ú
batch_sizer   r   Údevicec                 ó"  • [         R                  " U5      n[         R                  " [         R                  " XS9[         R                  " X#S9SS9n[         R                  " US S S2   SS9R                  5       nUS    R                  U SSS5      $ )N)r   Úij)Úindexingr   r   r   r   )r   r   ÚmeshgridÚarangeÚstackÚfloatÚrepeat)r   r   r   r   Úcoordss        r   Úmake_coords_gridr(      sq   € Ü�\Š\˜&Ó!€FÜ�^Š^œEŸLšL¨Ñ:¼E¿LºLÈÑ<ZÐeiÑj€FÜ�[Š[˜¡ " ™¨1Ñ-×3Ñ3Ó5€FØ�$‰<×Ñ˜z¨1¨a°Ó3Ð3r   Úup_maskÚfactorc           	      óŽ  • U R                   u  p4pVXR-  Xb-  p‡Uc  U[        R                  " XU4SSS9-  $ UR                  USSX"XV5      n[        R
                  " USS9n[        R                  " X -  SSS	9R                  X4SSSXV5      n	[        R                  " X-  SS9n	U	R                  S
SSSSS5      R                  X4Xx5      $ )a  Upsample flow by the input factor (default 8).

If up_mask is None we just interpolate.
If up_mask is specified, we upsample using a convex combination of its weights. See paper page 8 and appendix B.
Note that in appendix B the picture assumes a downsample factor of 4 instead of 8.
ÚbilinearT)Úsizer   r   r   é	   r   r   é   )Úkernel_sizeÚpaddingr   é   é   )
r   r   ÚinterpolateÚviewr   ÚsoftmaxÚunfoldÚsumÚpermuteÚreshape)
Úflowr)   r*   r   Únum_channelsr   r   Únew_hÚnew_wÚupsampled_flows
             r   Úupsample_flowr@      sÌ   € ð &*§Z¡ZÑ"€J˜aØ‘:˜q™zˆ5à�ØœŸš d¸°ÀjÐ`dÑeÑeÐeà�l‰l˜: q¨!¨V¸QÓB€GÜ�mŠm˜G¨Ñ+€Gä—X’X˜f™m¸ÀAÑF×KÑKÈJÐfgÐijÐlmÐopÓt€NÜ—Y’Y˜wÑ7¸QÑ?€Nà×!Ñ! ! Q¨¨1¨a°Ó3×;Ñ;¸JÐV[ÓcÐcr   )r,   N)Úcpu)Né   )Útypingr   r   Útorch.nn.functionalÚnnÚ
functionalr   r   ÚstrÚboolr   Úintr(   r@   © r   r   Ú<module>rK      s}   ðÝ ã ß Ð Ý ñW�Vð W¨Fð W¸#ð WÐ[cÐdhÑ[iõ Wñ4 ð 4¨ð 4°ð 4¸cõ 4ñd ¨&Ñ!1ð dÀ#ö dr   