+
    ÿäûjx  ã                   ó°  € ^ RI t ^ RIHt ^ RIHtHtHtHt ^ RI Ht ^ RI	t	^ RI
Hu Ht ^ RI	Ht ^ RIHt ^ RIHt ^ RIHt ]]]]]3,          t]]]]3,          ]3,          t]]]3,          tR	 R
 ltRR R lltR R R llt ! R R]P6                  4      t ! R R]P6                  4      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 llt#R# )#é    N)Úceil)ÚOptionalÚTupleÚUnionÚcast)Úwarn)Únn)Ú_pair)Útorch_version_lt)ÚValueCheckErrorc                ó¼   € V ^8„  d   QhR\         \        \        \        \        3,          3,          R\         \        \        \        \        3,          3,          RR/# )é   Úwindow_sizeÚstrideÚreturnN)r   Úintr   )Úformats   "ÚZC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\contrib\extract_patches.pyÚ__annotate__r   $   sQ   € ÷ Uñ U¤U¬3´´c¼3°hµÐ+?Õ%@ð UÌ%ÔPSÔUZÔ[^Ô`cÐ[cÕUdÐPdÕJeð UÐjnñ Uó    c                 óÒ  € \        \        \        \        3,          \        V 4      4      p \        \        \        \        3,          \        V4      4      p\        ;QJ d    R  V  4       F  '       g   K   RM	  RM! R  V  4       4      '       d   \        RV  R24      h\        ;QJ d    R V 4       F  '       g   K   RM	  RM! R V 4       4      '       d   \        RV R24      hR# )c              3   ó*   "  € T F	  q^ 8*  x € K  	  R# 5i©r   N© )Ú.0Úsizes   & r   Ú	<genexpr>Ú&_check_patch_params.<locals>.<genexpr>)   s   é € Ð
-¡˜�1Ž9£ùó   ‚TFz.window_size must contain positive values. Got Ú.c              3   ó*   "  € T F	  q^ 8*  x € K  	  R# 5ir   r   )r   Ústeps   & r   r   r   +   s   é € Ð
(¡˜�1Ž9£ùr   z)stride must contain positive values. Got N)r   r   r   r
   Úanyr   )r   r   s   &&r   Ú_check_patch_paramsr$   $   s¨   € Ü”uœS¤#˜X•¬¨kÓ(:Ó;€KÜ”%œœS˜•/¤5¨£=Ó1€F÷ ƒsÑ
-¡Ó
-‡s‡s‚sÑ
-¡Ó
-×-Ò-ÜÐ NÈ{ÈmÐ[\Ð]Ó^Ð^ß
ƒsÑ
(¡Ó
(‡s‡s‚sÑ
(¡Ó
(×(Ò(ÜÐ IÈ&ÈÐQRÐSÓTÐTñ )r   c                ó<   € V ^8„  d   QhR\         R\        R\        /# )r   ÚpaddingÚ	unpaddingr   )ÚPadTypeÚboolÚFullPadType)r   s   "r   r   r   /   s!   € ÷ 2ñ 2¤'ð 2´dð 2Ä{ñ 2r   c                ó>  € \        \        \        V 4      4      p \        V 4      R9  d   \	        V'       d   RMR R24      h\        V 4      ^8X  d&   \        V ^ ,          4      p\        V ^,          4      pMV R,          pV R,          p\        \
        W2,           4      # )zCreate argument for padding op.Ú	UnpaddingÚPaddingz? must be either an int, tuple of two ints or tuple of four ints:Nr   Nºr   NN)r   é   )r   ÚTuplePadTyper
   ÚlenÚAssertionErrorr*   )r&   r'   Úpad_vertÚpad_horzs   &&  r   Úcreate_padding_tupler5   /   s‡   € ä”<¤ w£Ó0€Gä
ˆ7ƒ|˜6Ô!Üß'‰{¨YÐ7Ð7vÐwó
ð 	
ô ˆ7ƒ|�qÔÜ˜ �Ó$ˆÜ˜ �Ó$‰à˜2•;ˆØ˜2•;ˆä”˜XÕ0Ó1Ð1r   c                ó*  € V ^8„  d   QhR\         \        \        \        \        3,          3,          R\         \        \        \        \        3,          3,          R\        \         \        \        \        \        3,          3,          ,          R\        /# ©r   Úoriginal_sizer   r   r   )r   r   r   r   r*   )r   s   "r   r   r   B   sw   € ÷ FXñ FXÜœœe¤C¬ H�oÐ-Õ.ðFXä”sœE¤#¤s (�OÐ+Õ,ðFXô ”Uœ3¤¤c¬3 h¥Ð/Õ0Õ1ðFXô ñ	FXr   c                ó¼  € \        \        \        \        3,          \        V 4      4      p \        \        \        \        3,          \        V4      4      pVf   Tp\        \        \        \        3,          \        V4      4      p\	        W4       V ^ ,          V^ ,          ,
          V^ ,          ,          pV ^,          V^,          ,
          V^,          ,          pV^ 8w  d   V^ ,          V,
          M^ p\        WQ^ ,          V ^ ,          ,
          4      pV^ 8w  d   V^,          V,
          M^ p\        Wa^,          V ^,          ,
          4      pV^,          ^ 8X  d   V^,          ;rxMV^,          p\        V^,          4      pV^,          ^ 8X  d   V^,          ;ršMV^,          p	\        V^,          4      p
\        V4      \        V4      \        V	4      \        V
4      3# )a2  Compute the ``(top, bottom, left, right)`` padding that makes sliding windows fit.

``padding = compute_padding(original_size, window_size, stride)`` returns four ints that, passed as ``padding`` to
:func:`extract_tensor_patches` and as ``unpadding`` to :func:`combine_tensor_patches`, make the last window of
``window_size`` at ``stride`` end on the padded border, so no row or column is dropped. With ``stride`` at most
``window_size`` the windows then cover every pixel. Each padding is split evenly, with the odd pixel at the bottom
or right, and an image smaller than one window is padded to one window.

Args:
    original_size: the image size ``(H, W)``, or one int for both.
    window_size: the size of the sliding window used while extracting patches.
    stride: the stride of the sliding window. Default: ``window_size``.

Return:
    The required padding as a tuple of four ints ``(top, bottom, left, right)``.

Raises:
    ValueCheckError: if a ``window_size`` or ``stride`` component is below 1.

See Also:
    - :func:`extract_tensor_patches`: takes this as ``padding``.
    - :func:`combine_tensor_patches`: takes this as ``unpadding``.

Example:
    >>> image = torch.arange(12).view(1, 1, 4, 3)
    >>> padding = compute_padding((4,3), (3,3))
    >>> out = extract_tensor_patches(image, window_size=(3, 3), stride=(3, 3), padding=padding)
    >>> combine_tensor_patches(out, original_size=(4, 3), window_size=(3, 3), stride=(3, 3), unpadding=padding)
    tensor([[[[ 0,  1,  2],
              [ 3,  4,  5],
              [ 6,  7,  8],
              [ 9, 10, 11]]]])

)r   r   r   r
   r$   Úmaxr   )r8   r   r   Úremainder_verticalÚremainder_horizontalÚvertical_paddingÚhorizontal_paddingÚtop_paddingÚbottom_paddingÚleft_paddingÚright_paddings   &&&        r   Úcompute_paddingrC   B   s—  € ôN œœs¤C˜x�¬%°Ó*>Ó?€MÜ”uœS¤#˜X•¬¨kÓ(:Ó;€KØ‚~ØˆÜ”%œœS˜•/¤5¨£=Ó1€FÜ˜Ô,à'¨Õ*¨[¸­^Õ;¸vÀa½yÕHÐØ)¨!Õ,¨{¸1­~Õ=ÀÈÅÕJÐð :LÈqÔ9P�v˜a•yÐ#5Ö5ÐVWÐäÐ+¸­^¸mÈAÕ>NÕ-NÓOÐà=QÐUVÔ=V˜ �Ð%9Ö9Ð\]ÐÜÐ/¸QµÀ-ÐPQÕBRÕ1RÓSÐà˜!Õ˜qÔ Ø'7¸1Õ'<Ð<ˆ�nà&¨!Õ+ˆÜÐ.°Õ2Ó3ˆà˜AÕ Ô"Ø'9¸QÕ'>Ð>ˆ�}à)¨QÕ.ˆÜÐ/°!Õ3Ó4ˆäˆ{ÓœS Ó0´#°lÓ2CÄSÈÓEWÐWÐWr   c                   óX   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RtVtV ;t	# )ÚExtractTensorPatchesa‡  Cut an image into sliding-window patches with stored settings (module form).

``extract = ExtractTensorPatches(window_size, stride, padding)`` stores its arguments, and
``patches = extract(image)`` is :func:`extract_tensor_patches` on a ``(B, C, H, W)`` image, returning
``(B, N, C, h, w)`` patches.

Convention:
    See the Convention block on :func:`extract_tensor_patches`.

Args:
    window_size: the size ``(h, w)`` of the sliding window and of each patch, or one int for both.
    stride: stride of the sliding window, an int or ``(sh, sw)``. Default: 1.
    padding: zero padding, or cropping where negative: an int, ``(ph, pw)`` or ``(top, bottom, left, right)``.
    allow_auto_padding: whether to pad the image as :func:`compute_padding` computes when the windows do not fit.

Shape:
    - Input: ``(B, C, H, W)``
    - Output: ``(B, N, C, h, w)``

Raises:
    ValueCheckError: if a ``window_size`` or ``stride`` component is below 1; raised from the constructor.

See Also:
    - :func:`extract_tensor_patches`: the one-call form.
    - :class:`CombineTensorPatches`: puts the patches back into an image.

Examples:
    >>> input = torch.arange(9.).view(1, 1, 3, 3)
    >>> patches = ExtractTensorPatches((2, 3))(input)
    >>> input
    tensor([[[[0., 1., 2.],
              [3., 4., 5.],
              [6., 7., 8.]]]])
    >>> patches[:, -1]
    tensor([[[[3., 4., 5.],
              [6., 7., 8.]]]])

c          
      óŽ   <€ V ^8„  d   QhRS[ S[S[S[S[3,          3,          RS[ S[S[S[S[3,          3,          RS[RS[RR/# )r   r   r   r&   Úallow_auto_paddingr   N)r   r   r   r(   r)   )r   Ú__classdict__s   "€r   r   Ú!ExtractTensorPatches.__annotate__³   sa   ø€ ÷ ;ñ ;á™3¡¡c©3 h¥Ð/Õ0ð;ñ ‘c™5¡¡c �?Ð*Õ+ð;ñ ð	;ñ
 !ð;ð 
ñ;r   c                ój   <€ \         SV `  4        \        W4       Wn        W n        W0n        W@n        R # ©N)ÚsuperÚ__init__r$   r   r   r&   rG   )Úselfr   r   r&   rG   Ú	__class__s   &&&&&€r   rM   ÚExtractTensorPatches.__init__³   s.   ø€ ô 	‰ÑÔÜ˜KÔ0Ø8CÔØ39ŒØ 'ŒØ(:Ör   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# ©r   Úinputr   ©ÚtorchÚTensor)r   rH   s   "€r   r   rI   Á   s#   ø€ ÷ 
ñ 
™UŸ\™\ð 
©e¯l©lñ 
r   c                ór   € \        VV P                  V P                  V P                  V P                  R7      # )zÜExtract the sliding-window patches of a ``(B, C, H, W)`` image.

Args:
    input: the image, ``(B, C, H, W)``.

Returns:
    The patches, ``(B, N, C, h, w)``, with ``N`` window positions and ``(h, w)`` the window size.

)r   r&   rG   )Úextract_tensor_patchesr   r   r&   rG   ©rN   rS   s   &&r   ÚforwardÚExtractTensorPatches.forwardÁ   s4   € ô &ØØ×ÑØ—;‘;Ø—L‘LØ#×6Ñ6ô
ð 	
r   )rG   r&   r   r   ©é   r   F©
Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__rM   rZ   Ú__static_attributes__Ú__classdictcell__Ú__classcell__©rO   rH   s   @@r   rE   rE   ‹   s$   ù‡ € ñ%÷N;õ ;÷
÷ 
ð 
r   rE   c                   óX   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RtVtV ;t	# )ÚCombineTensorPatchesaú  Reassemble sliding-window patches into an image with stored settings (module form).

``combine = CombineTensorPatches(original_size, window_size, stride, unpadding)`` stores its arguments, and
``image = combine(patches)`` is :func:`combine_tensor_patches` on ``(B, N, C, h, w)`` patches, returning a
``(B, C, H, W)`` image. Unlike :func:`combine_tensor_patches`, ``stride`` defaults to ``window_size``;
:class:`ExtractTensorPatches` defaults it to 1, so pass the same ``stride`` to both.

Convention:
    See the Convention block on :func:`combine_tensor_patches`.

Args:
    original_size: the size ``(H, W)`` of the image the patches were extracted from, and of the output.
    window_size: the size of the sliding window used while extracting patches.
    stride: stride of the sliding window. Default: ``window_size``.
    unpadding: the padding used while extracting the patches, removed from the output.
    allow_auto_unpadding: whether to remove the padding :func:`compute_padding` computes when the windows do not
        fit ``original_size``; pass it when the patches were extracted with ``allow_auto_padding=True``.

Shape:
    - Input: ``(B, N, C, h, w)``
    - Output: ``(B, C, H, W)``

Raises:
    ValueCheckError: if a ``window_size`` or ``stride`` component is below 1; raised from the constructor.

See Also:
    - :func:`combine_tensor_patches`: the one-call form.
    - :class:`ExtractTensorPatches`: cuts the patches this module puts back.

Example:
    >>> out = extract_tensor_patches(torch.arange(16).view(1, 1, 4, 4), window_size=(2, 2), stride=(2, 2))
    >>> CombineTensorPatches(original_size=(4, 4), window_size=(2, 2))(out)
    tensor([[[[ 0,  1,  2,  3],
              [ 4,  5,  6,  7],
              [ 8,  9, 10, 11],
              [12, 13, 14, 15]]]])

c                óº   <€ V ^8„  d   QhRS[ S[S[3,          RS[S[S[ S[S[3,          3,          RS[S[S[S[ S[S[3,          3,          ,          RS[RS[RR/# )r   r8   r   r   r'   Úallow_auto_unpaddingr   N)r   r   r   r   r(   r)   )r   rH   s   "€r   r   Ú!CombineTensorPatches.__annotate__ü   sx   ø€ ÷ ?ñ ?á™S¡#˜X•ð?ñ ™3¡¡c©3 h¥Ð/Õ0ð?ñ ™™s¡E©#©s¨(¥OÐ3Õ4Õ5ð	?ñ
 ð?ñ #ð?ð 
ñ?r   c                ó�   <€ \         SV `  4        \        Y#e   TMT4       Wn        W n        Ve   TMTV n        W@n        WPn        R # rK   )rL   rM   r$   r8   r   r   r'   rk   )rN   r8   r   r   r'   rk   rO   s   &&&&&&€r   rM   ÚCombineTensorPatches.__init__ü   sE   ø€ ô 	‰ÑÔÜ˜KÒ3E©È;ÔWØ.;ÔØ8CÔØ=CÒ=O±6ÐU`ˆŒØ"+ŒØ*>Ö!r   c                óN   <€ V ^8„  d   QhRS[ P                  RS[ P                  /# rR   rT   )r   rH   s   "€r   r   rl     s#   ø€ ÷ 
ñ 
™UŸ\™\ð 
©e¯l©lñ 
r   c           	     óˆ   € \        VV P                  V P                  V P                  V P                  V P
                  R7      # )zÑReassemble ``(B, N, C, h, w)`` patches into a ``(B, C, H, W)`` image.

Args:
    input: the patches, ``(B, N, C, h, w)``.

Returns:
    The image, ``(B, C, H, W)`` with ``(H, W)`` equal to ``original_size``.

)r   r'   rk   )Úcombine_tensor_patchesr8   r   r   r'   rk   rY   s   &&r   rZ   ÚCombineTensorPatches.forward  s=   € ô &ØØ×ÑØ×ÑØ—;‘;Ø—n‘nØ!%×!:Ñ!:ô
ð 	
r   )rk   r8   r   r'   r   )Nr   Fr^   rg   s   @@r   ri   ri   Ô   s$   ù‡ € ñ%÷N?õ ?÷ 
÷ 
ð 
r   ri   c                ó®   € V ^8„  d   QhR\         \        \        3,          R\         \        \        3,          R\         \        \        3,          R\        /# r7   )r   r   r)   )r   s   "r   r   r      sF   € ÷ ñ ¤E¬#¬s¨(¥Oð Ä%ÌÌSÈÅ/ð Ô[`ÔadÔfiÐaiÕ[jð Ôosñ r   c                 ó&  € V ^ ,          V^ ,          ,
          V^ ,          ,          pV ^,          V^,          ,
          V^,          ,          pV ^ ,          V^ ,          8¬  ;'       d.    V ^,          V^,          8¬  ;'       d    V^ 8H  ;'       d    V^ 8H  # )r   r   )r8   r   r   r;   r<   s   &&&  r   Ú_check_patch_fitru      s•   € Ø'¨Õ*¨[¸­^Õ;¸vÀa½yÕHÐØ)¨!Õ,¨{¸1­~Õ=ÀÈÅÕJÐð 	�aÕ˜K¨�NÑ*÷ 	$ð 	$Ø˜!Õ ¨A¥Ñ.÷	$ð 	$à  AÑ%÷	$ð 	$ð  !Ñ#ð	r   c                ó‚  € V ^8„  d   QhR\         P                  R\        \        \        \        \        3,          3,          R\        \        \        \        \        3,          3,          R\        \        \        \        \        3,          3,          R\
        R\        R\        \        ,          R\         P                  /# )	r   Úpatchesr8   r   r   rk   r'   Úepsr   )	rU   rV   r   r   r   r)   r(   r   Úfloat)r   s   "r   r   r   /  s¤   € ÷ P"ñ P"Ü�\‰\ðP"äœœe¤C¬ H�oÐ-Õ.ðP"ô ”sœE¤#¤s (�OÐ+Õ,ðP"ô ”#”uœS¤#˜X•Ð&Õ'ð	P"ô
 ðP"ô ðP"ô 
”%�ðP"ô ‡\�\ñP"r   c                ó6
  € V P                   ^8w  d   \        RV P                   24      h\        \        \
        \
        3,          \        V4      4      p\        \        \
        \
        3,          \        V4      4      p\        \        \
        \
        3,          \        V4      4      p\        W#4       V^ ,          V^ ,          8„  V^,          V^,          8„  ,          '       d   \        RV RV R24      h\        VRR7      p\        V4      '       gI   \        WV4      '       g7   V'       g   \        RV RV R	V R
2^R7       M\        \        WVR7      4      p\        V4      pVe   \        P                  ! R\        ^R7       V P                   p	V P#                  4       '       * ;'       d    V P%                  4       '       * p
V
'       dG   \'        WW#Wx4      pV P(                  P*                  R8X  d   \-        ^^	^ 4      '       g   \/        W4      # V P                   \0        P2                  \0        P4                  39   pV P%                  4       '       d   V P6                  P                   MV P                   pV
'       g	   V'       d   \0        P8                  p\0        P:                  ! V P                  ^ ,          V P                  ^,          V^ ,          V^,          V P(                  VR7      pV'       d!   \<        P>                  ! V\A        V4      4      pVP                  R,          pV PC                  ^ ^^^^4      PE                  ^^4      p \<        PF                  ! WâVR7      p\<        PH                  ! VWòVR7      pRVRVRV/pV P%                  4       '       d?   V P6                  V PJ                  3 Uu. uF  p\<        PH                  ! RRV/VB NK  	  ppM(\<        PH                  ! RRV PM                  V4      /VB .pV'       db   \<        P>                  ! TV Uu. uF  pV) NK  	  up4      pV UUu. uF+  p\<        P>                  ! TV Uu. uF  pV) NK  	  up4      NK-  	  ppp\0        PN                  ! V^ 8H  \0        PP                  ! V4      V4      pV P%                  4       '       d4   \0        PR                  ! V^ ,          V,          V^,          V,          4      MV^ ,          V,          pVPM                  V	4      # u upi u upi u upi u uppi )ao  Reassemble sliding-window patches into an image, averaging where they overlap.

``image = combine_tensor_patches(patches, original_size, window_size, stride)`` takes ``(B, N, C, h, w)``
patches and returns the ``(B, C, H, W)`` image of size ``original_size``. Pass the ``stride`` used for the
extraction and its ``padding`` as ``unpadding``. With ``stride`` at most ``window_size``, a round trip returns
the input when the extraction padding is non-negative and makes the windows fit, or when both auto flags are set
and ``padding`` and ``unpadding`` are zero. It is exact for integer and ``bool`` patches (below :math:`2^{24}` on
MPS before torch 2.9), and exact up to rounding where floating patches overlap.

Convention:
    - Overlapping patches are averaged: each pixel is divided by the number of patches that cover it, where
      :func:`torch.nn.functional.fold` sums them. A pixel that no patch covers (patches that do not fit) is 0.
    - The output keeps the dtype of the patches. Integer patches are averaged exactly in ``int64``, with the mean
      truncated toward zero (on MPS before torch 2.9 they go through ``float32``, exact up to :math:`2^{24}`);
      ``bool`` patches are True where any covering patch is True; ``float16`` and ``bfloat16`` patches are summed
      in ``float32``.
    - ``unpadding`` and ``allow_auto_unpadding`` follow the ``padding`` and ``allow_auto_padding`` rules of
      :func:`extract_tensor_patches`; without either, patches that do not fit ``original_size`` give a warning.
    - This function takes ``allow_auto_unpadding`` before ``unpadding``.
    - An empty batch is reconstructed with the same spatial size and unpadding as a non-empty one.

Args:
    patches: the patches, ``(B, N, C, h, w)``.
    original_size: the size ``(H, W)`` of the image the patches were extracted from, and of the output.
    window_size: the size of the sliding window used while extracting patches.
    stride: stride of the sliding window. Required.
    allow_auto_unpadding: whether to remove the padding :func:`compute_padding` computes when the windows do not
        fit ``original_size``.
    unpadding: the padding used while extracting the patches, removed from the output.
    eps: deprecated, has no effect. Each covered pixel is divided by its exact overlap count and a pixel no patch
        covers is 0.

Return:
    The combined patches in an image tensor with shape ``(B, C, H, W)``.

Raises:
    ValueError: if ``patches`` is not 5-D.
    ValueCheckError: if a ``window_size`` or ``stride`` component is below 1.
    AssertionError: if ``stride`` is larger than ``window_size``, which leaves pixels uncovered, or if
        ``unpadding`` is a tuple of other than two or four ints.
    RuntimeError: if the number or size of the patches does not match ``original_size``, ``window_size``, ``stride``
        and ``unpadding``.

See Also:
    - :func:`extract_tensor_patches`: cuts the patches this function puts back.
    - :class:`CombineTensorPatches`: the module form.
    - :func:`compute_padding`: the ``unpadding`` that makes the windows fit.

Example:
    >>> out = extract_tensor_patches(torch.arange(16).view(1, 1, 4, 4), window_size=(2, 2), stride=(2, 2))
    >>> combine_tensor_patches(out, original_size=(4, 4), window_size=(2, 2), stride=(2, 2))
    tensor([[[[ 0,  1,  2,  3],
              [ 4,  5,  6,  7],
              [ 8,  9, 10, 11],
              [12, 13, 14, 15]]]])

z/Invalid input shape, we expect BxNxCxHxW. Got: zStride=z- should be less than or equal to Window size=z, information is missingT)r'   ú6The window will not fit into the image. 
Window size: ú	
Stride: ú
Image size: aH  
This means we probably cannot correctly recombine patches. By enabling `allow_auto_unpadding`, the input will be unpadded to fit the window and stride.
If the patches have been obtained through `extract_tensor_patches` with the correct padding or the argument `allow_auto_padding`, this will result in a correct reconstruction.©Ú
stacklevel©r8   r   r   zº`eps` is deprecated and has no effect: each covered pixel is divided by its exact overlap count and a pixel no patch covers is 0. It will be removed in a future release; stop passing it.Úmps)ÚdeviceÚdtyper.   )Úkernel_sizer   )rS   Úoutput_sizer„   r   r…   r„   r   rS   r   )*ÚndimÚ
ValueErrorÚshaper   r   r   r
   r$   r2   r5   r#   ru   r   rC   ÚwarningsÚDeprecationWarningrƒ   Úis_floating_pointÚ
is_complexÚ_patch_target_indexr‚   Útyper   Ú_combine_integer_patchesrU   Úfloat16Úbfloat16ÚrealÚfloat32ÚonesÚFÚpadÚlistÚpermuteÚflattenÚunfoldÚfoldÚimagÚtoÚwhereÚ	ones_likeÚcomplex)rw   r8   r   r   rk   r'   rx   Úunpadding_tupleÚhas_unpaddingÚ	out_dtypeÚ
is_integerÚtargetÚhalfÚ
work_dtypeÚones_tensorÚrestored_sizeÚunfold_onesÚnorm_mapÚfold_kwargsÚpartÚfoldedÚiÚcountÚrestoreds   &&&&&&&                 r   rq   rq   /  s  € ðD ‡|�|�qÔÜÐJÈ7Ï=É=È/ÐZÓ[Ð[äœœs¤C˜x�¬%°Ó*>Ó?€MÜ”uœS¤#˜X•¬¨kÓ(:Ó;€KÜ”%œœS˜•/¤5¨£=Ó1€FÜ˜Ô,àˆq�	�K •NÑ" v¨a¥y°;¸qµ>Ñ'A×BÔBÜØ�f�XÐJÈ;È-ÐWoÐpó
ð 	
ô +¨9ÀÔE€OÜˆ×ÒÔ(8¸ÐU[×(\Ò(\ß#ÜØIÈ+ÈÐV`ÐagÐ`hð iØ,˜oð .cðcð öô 3Ü¨mÐ]cÔdóˆOô ˜Ó(€Mà
‚Ü�ŠðcäØõ		
ð —‘€IØ×.Ñ.Ó0Ô0×MÐM¸×9KÑ9KÓ9MÔ5M€Jßä$ W¸[ÐRaÓqˆð —‘×#Ñ# uÔ,Ô1AÀ!ÀQÈ×1JÒ1JÜ+¨GÓ<Ð<ð �=‰=œUŸ]™]¬E¯N©NÐ;Ñ;€DØ'.×'9Ñ'9×';Ò';�—‘×#Ò#ÀÇÁ€Jß—TÜ—]‘]ˆ
Ü—*’*Ø�‰�aÕ˜'Ÿ-™-¨Õ*¨M¸!Õ,<¸mÈAÕ>NÐW^×WeÑWeÐmwô€K÷ Ü—e’e˜K¬¨oÓ)>Ó?ˆØ×%Ñ% bÕ)€MØ�o‰o˜a  A q¨!Ó,×4Ñ4°Q¸Ó:€GÜ—(’(˜;ÈÔO€KÜ�vŠv˜K°]ÐdjÔk€HØ  -°ÀÈXÐW]Ð^€KØ×Ñ×ÒØAHÇÁÈwÏ|É|Ñ@\Ó]Ñ@\¸”!—&’&Ñ3˜tÐ3 {Ô3Ñ@\ˆÐ]ˆä—&’&ÑE˜wŸz™z¨*Ó5ÐE¸ÑEÐFˆßÜ—5’5˜±Ó#@±¨1 Q£B±Ñ#@ÓAˆÙIOÔPÉÀ”!—%’%˜©?Ó;©? a ›r©?Ñ;Ö<ÉˆÑPô �KŠK˜ A™¤u§¢°xÓ'@À(ÓK€EØFM×FXÑFX×FZÒFZŒu�}Š}˜V A�Y¨Õ.°°qµ	¸EÕ0AÔBÐ`fÐghÕ`iÐlqÕ`q€HØ�;‰;�yÓ!Ð!ùò ^ùò $AùÚ;ùÓPs$   Î8!TÐ!T
Ð9TÑTÑTÔTc                ó~  € V ^8„  d   QhR\         P                  R\        \        \        3,          R\        \        \        3,          R\        \        \        3,          R\        R\
        R\        \         P                  \        \        \        \        \        3,          \        \        \        3,          3,          /# )r   rw   r8   r   r   r¡   r¢   r   )rU   rV   r   r   r*   r)   )r   s   "r   r   r   Â  s™   € ÷ Kñ KÜ�\‰\ðKäœœc˜•?ðKô ”sœC�x•ðKô ”#”s�(�Oð	Kô
 !ðKô ðKô Œ5�<‰<œœs¤C¬¬cÐ1Õ2´E¼#¼s¸(µOÐCÕDñKr   c                óZ  € V P                   ^,          pV'       d   TMR	w  rxršV^ ,          V	,           V
,           V^,          V,           V,           rË\        P                  ! W¼,          V P                  R7      P	                  ^^W¼4      p\        WÒV4      pV.V P                   R,          O5VP                   ^,          .VP                   R,          O58w  dA   \        R\        V P                   4       RVP                   ^,           RV RW¼3 RV R24      hVP                  4       WxWš3W¼33# )
zhReturn the target pixel of every patch element, the (left, right, top, bottom) crop and the padded size.)r‚   :é   NNzGiven patches of shape z, expected z patches of window size z for output_size=z and stride=r    )r   r   r   r   )	rˆ   rU   Úaranger‚   ÚviewÚ_extract_tensor_patchesndÚRuntimeErrorÚtupler™   )rw   r8   r   r   r¡   r¢   ÚNÚpad_lÚpad_rÚpad_tÚpad_bÚHrÚWrÚindexÚindex_patchess   &&&&&&         r   r�   r�   Â  s  € ð 	�‰�aÕ€Aß4A¡À|Ñ€E�%Ø˜1Õ Õ%¨Õ-¨}¸QÕ/?À%Õ/GÈ%Õ/OˆÜ�LŠL˜�¨¯©Ô8×=Ñ=¸aÀÀBÓK€EÜ-¨eÀ&ÓI€MØ	ÐˆG�M‰M˜"ÕÑ =×#6Ñ#6°qÕ#9Ð"T¸M×<OÑ<OÐPRÕ<SÑ"TÔTÜØ%¤e¨G¯M©MÓ&:Ð%;¸;À}×GZÑGZÐ[\ÕG]ÐF^Ð^vØˆmÐ,¨b¨X¨J°lÀ6À(È!ðMó
ð 	
ð × Ñ Ó" U°5Ð$@À2À(ÐJÐJr   c          
      óü   € V ^8„  d   QhR\         P                  R\        \         P                  \        \        \        \        \        3,          \        \        \        3,          3,          R\         P                  /# )r   rw   r¥   r   ©rU   rV   r   r   )r   s   "r   r   r   Ø  sW   € ÷ '!ñ '!Ü�\‰\ð'!Ü#(¬¯©´u¼SÄ#ÄsÌCÐ=OÕ7PÔRWÔX[Ô]`ÐX`ÕRaÐ)aÕ#bð'!ä
‡\�\ñ'!r   c                 óÈ  € Vw  r#w  rEV P                   ^ ,          V P                   ^,          rvV P                  \        P                  4      P	                  ^ ^^^^4      P                  ^4      pV P                  \        P                  8H  p	V	'       d   \        P                  ! VR4      p\        P                  ! WgWE,          \        P                  V P                  R7      p
V P                  \        P                  8X  d   V
P                  RW(4      ^ 8g  pEMt\        P                  ! WE,          \        P                  V P                  R7      pVP                  ^ V\        P                  ! V4      4      pV^ 8„  pVP                  ^4      pWÂ,          p\        P                   ! WŽRR7      pV
P                  RW(Wþ,          ,
          4      pV
P                  RW/4      \        P                   ! VVRR7      ,           pV	'       dC   \        P"                  ! V\        P                  ! VR4      \        P$                  ! V4      4      pMGW»^ 8  \        P&                  ! VV4      ^ 8g  ,          P                  \        P                  4      ,           p\(        P*                  ! VP-                  WgWE4      V Uu. uF  pV) NK  	  up4      pVP                  V P                  4      # u upi )r   )rƒ   r‚   Útrunc)Úrounding_modeÚfloorlûÿÿÿ         éÿÿÿÿ)rˆ   r�   rU   Úint64r˜   r™   rƒ   Úuint64Úbitwise_xorÚzerosr‚   r)   Ú	index_addÚ
index_add_rŸ   Ú	clamp_minÚdivrž   Ú
zeros_likeÚ	remainderr•   r–   r¶   )rw   r¥   Ú
flat_indexÚpadsr¿   rÀ   ÚBÚCÚvaluesÚ
unsigned64rÍ   ÚoutÚcountsÚcoveredr°   ÚqÚsum_rÚps   &&                r   r�   r�   Ø  s  € ð "(Ñ€J‘h�rØ�=‰=˜Õ˜WŸ]™]¨1Õ-€qØ�Z‰ZœŸ™Ó$×,Ñ,¨Q°°1°a¸Ó;×CÑCÀAÓF€Fð —‘¤%§,¡,Ñ.€JßÜ×"Ò" 6¨8Ó4ˆÜ�KŠK˜˜b�g¬U¯[©[ÀÇÁÔP€EØ‡}�}œŸ
™
Ô"à�o‰o˜b *Ó5¸Ñ:Šô
 —’˜R�W¬E¯K©KÀÇÁÔOˆØ×"Ñ" 1 j´%·/²/À*Ó2MÓNˆØ˜1‘*ˆØ×!Ñ! !Ó$ˆØÕ"ˆÜ�IŠI�f°7Ô;ˆØ—‘  J¸½Õ0BÓCˆØ�o‰o˜b *Ó0´5·9²9¸UÀFÐZaÔ3bÕbˆßô —+’+˜g¤u×'8Ò'8¸¸hÓ'GÌ×IYÒIYÐZ]ÓI^Ó_‰Cð  ™'¤e§o¢o°e¸VÓ&DÈÑ&IÕJ×NÑNÌuÏ{É{Ó[Õ[ˆCä
�%Š%�—‘˜˜rÓ&±TÓ(:±T°¨!«±TÑ(:Ó
;€CØ�6‰6�'—-‘-Ó Ð ùò );s   Ê1K
c                ó¤   € V ^8„  d   QhR\         P                  R\        \        R3,          R\        \        R3,          R\         P                  /# )r   rS   Úwindow_sizes.Ústridesr   rÄ   )r   s   "r   r   r     sD   € ÷ 'ñ 'Ü�<‰<ð'Ü',¬S°#¨X¥ð'ÜAFÄsÈCÀxÅð'ä
‡\�\ñ'r   c                 ó  a€ \        ^V P                  4       4      o\        SW4       F  w  r4pV P                  W4V4      p K  	  V P                  ! ^ .SO^NV3R lS 4       O5!  P                  4       p V P                  ^\        S4      4      # )r   c              3   óF   <"  € T F  q\        S4      ,           x € K  	  R # 5irK   )r1   )r   ÚdimÚdimss   & €r   r   Ú,_extract_tensor_patchesnd.<locals>.<genexpr>  s   øé € Ð(IÁD¸S¬s°4«y¯ªÃDùs   ƒ!)Úrangerå   Úziprš   r˜   Ú
contiguousr™   r1   )rS   rá   râ   rå   Ú
patch_sizer   ræ   s   &&&   @r   r·   r·     s   ø€ ô ��E—I‘I“KÓ €DÜ#& t¨\Ö#CÑˆ˜Ø—‘˜S¨fÓ5Šñ $Dà�MŠM˜!ÐJ˜dÐJ AÐJÔ(IÁDÓ(IÓJ×UÑUÓW€EØ�=‰=˜œC ›IÓ&Ð&r   c                ó  € V ^8„  d   QhR\         P                  R\        \        \        \        \        3,          3,          R\        \        \        \        \        3,          3,          R\
        R\        R\         P                  /# )r   rS   r   r   r&   rG   r   )rU   rV   r   r   r   r(   r)   )r   s   "r   r   r     s€   € ÷ bAñ bAÜ�<‰<ðbAä”sœE¤#¤s (�OÐ+Õ,ðbAô ”#”uœS¤#˜X•Ð&Õ'ðbAô ð	bAô
 ðbAô ‡\�\ñbAr   c           	     ó^  € \         P                  ! V 4      '       g   \        R\        V 4       24      h\	        V P
                  4      ^8w  d   \        RV P
                   24      h\        \        \        \        3,          \        V4      4      p\        \        \        \        3,          \        V4      4      p\        W4       V P
                  ^,          ^ 8X  d   \        R4      hV P
                  R
,          V P
                  R,          3p\        V4      p\        V4      '       gI   \        WQV4      '       g7   V'       g   \        RV RV RV R2^R7       M\        \!        WQVR	7      4      p\        V4      '       d!   \"        P$                  ! V \'        V4      4      p \)        WV4      # )ab  Cut an image into sliding-window patches stacked along a new patch dimension.

``patches = extract_tensor_patches(image, window_size, stride)`` takes a ``(B, C, H, W)`` image and returns its
``(B, N, C, h, w)`` patches, where ``(h, w)`` is ``window_size`` and ``N`` is the number of window positions.

Convention:
    - Patches are stacked row-major over the grid of window positions, left to right and then top to bottom, the
      order of :func:`torch.nn.functional.unfold`.
    - ``window_size``, ``stride`` and a 2-tuple ``padding`` are ``(height, width)``, or one int for both. A positive
      ``padding`` adds zeros and a negative one crops. A 4-tuple is ``(top, bottom, left, right)``, not the
      ``(left, right, top, bottom)`` of :func:`torch.nn.functional.pad`; a 2-tuple ``(ph, pw)`` adds ``ph`` rows
      above and below and ``pw`` columns left and right.
    - A window that does not fit warns and drops the last rows or columns; an image smaller than the window warns
      and then raises. ``allow_auto_padding=True`` pads instead, as :func:`compute_padding` computes.
    - A non-zero ``padding`` switches off both the fit warning and ``allow_auto_padding``, so a padding too small
      for the window drops the last rows or columns silently. An all-zero ``padding`` counts as none.
    - The ``ValueCheckError`` (a ``ValueError``) for a ``window_size`` or ``stride`` component below 1 is raised
      up front, also under ``python -O`` and ``disable_checks()``, here, in :func:`combine_tensor_patches` and
      :func:`compute_padding`, and at construction of :class:`ExtractTensorPatches` and
      :class:`CombineTensorPatches`.
    - An empty batch gives an empty output with the same ``N``, ``C``, ``h`` and ``w`` as a non-empty one.

Args:
    input: the image to extract the patches from, ``(B, C, H, W)`` with ``C`` at least 1.
    window_size: the size ``(h, w)`` of the sliding window and of each patch, or one int for both.
    stride: stride of the sliding window, an int or ``(sh, sw)``.
    padding: zero padding, or cropping where negative: an int, ``(ph, pw)`` or ``(top, bottom, left, right)``.
    allow_auto_padding: whether to pad the image as :func:`compute_padding` computes when the windows do not fit.

Returns:
    The extracted patches, ``(B, N, C, h, w)``.

Raises:
    TypeError: if ``input`` is not a tensor.
    ValueError: if ``input`` is not 4-D or has no channel.
    ValueCheckError: if a ``window_size`` or ``stride`` component is below 1.
    AssertionError: if ``padding`` is a tuple of other than two or four ints.
    RuntimeError: if the image, after any padding, is smaller than the window.

See Also:
    - :class:`ExtractTensorPatches`: the module form.
    - :func:`combine_tensor_patches`: puts the patches back into an image.
    - :func:`compute_padding`: the ``padding`` that makes the windows fit.

Examples:
    >>> input = torch.arange(9.).view(1, 1, 3, 3)
    >>> patches = extract_tensor_patches(input, (2, 3))
    >>> input
    tensor([[[[0., 1., 2.],
              [3., 4., 5.],
              [6., 7., 8.]]]])
    >>> patches[:, -1]
    tensor([[[[3., 4., 5.],
              [6., 7., 8.]]]])

z,Input input type is not a torch.Tensor. Got z-Invalid input shape, we expect BxCxHxW. Got: z>extract_tensor_patches requires a non-empty channel dimension.r{   r|   r}   z—
This means that the final incomplete patches will be dropped. By enabling `allow_auto_padding`, the input will be padded to fit the window and stride.r~   r€   éþÿÿÿrÉ   )rU   Ú	is_tensorÚ	TypeErrorrŽ   r1   rˆ   r‡   r   r   r   r
   r$   r5   r#   ru   r   rC   r•   r–   r—   r·   )rS   r   r   r&   rG   r8   Úpadding_tuples   &&&&&  r   rX   rX     sf  € ô~ �?Š?˜5×!Ò!ÜÐFÄtÈEÃ{ÀmÐTÓUÐUä
ˆ5�;‰;Ó˜1ÔÜÐHÈÏÉÈÐVÓWÐWô ”uœS¤#˜X•¬¨kÓ(:Ó;€KÜ”%œœS˜•/¤5¨£=Ó1€FÜ˜Ô,Ø‡{�{�1…~˜ÔÜÐYÓZÐZØ—[‘[ •_ e§k¡k°"¥oÐ6€Mô )¨Ó1€MÜˆ}×ÒÔ&6°}ÐSY×&ZÒ&Zß!ÜØIÈ+ÈÐV`ÐagÐ`hð iØ,˜oð .IðIð öô 1Ü¨mÐ]cÔdóˆMô ˆ=×ÒÜ—’�eœT -Ó0Ó1ˆä$ U¸Ó@Ð@r   )FrK   )Fr   Nr\   )$r‰   Úmathr   Útypingr   r   r   r   r   rU   Útorch.nn.functionalr	   Ú
functionalr•   Útorch.nn.modules.utilsr
   Úkornia.core._compatr   Úkornia.core.exceptionsr   r   r*   r0   r(   r$   r5   rC   ÚModulerE   ri   ru   rq   r�   r�   r·   rX   r   r   r   Ú<module>rú      sÈ   ðó$ Ý ß /Ó /Ý ã ß Ð Ý Ý (å 0Ý 2à�C˜˜c 3Ð&Õ'€Ø�U˜3 ˜8•_ kÐ1Õ2€Ø
��\Ð!Õ
"€õU÷2÷&FXôRF
˜2Ÿ9™9ô F
ôRI
˜2Ÿ9™9ô I
õX÷P"õfKõ,'!õT'÷bAñ bAr   