
    \h              
           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	            `/var/www/fran/franai/venv/lib/python3.13/site-packages/torchvision/models/optical_flow/_utils.pyr   r      s    99RS>DA &&1v2&6LEIQ!#E1uE	QU#a'iiB7O==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^^ELL:ELL<ZeijF[["1-335F$<z1a33r   up_maskfactorc           	         U R                   u  p4pVXR-  Xb-  pU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     &*ZZ"Ja:qz5dj`deeell:q!VQBGmmG+GXXfmAFKKJfgijlmoptNYYw7Q?N!!!Q1a3;;JV[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[cdh[i W4 4 4 4c 4d&!1 d# dr   