+
    úäûjü  ã                   ód   € ^ RI HtHtHtHtHt ^ RIt^ RIHt	 ^ RI
Ht ^ RIHt  ! R R]4      tR# )é    )ÚAnyÚDictÚListÚOptionalÚUnionN)Úrandom_generator)ÚMixAugmentationBaseV2)ÚDataKeyc                   ój   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RtVt	V ;t
# )
ÚPatchMixa8  Replace a square patch with that of a paired sample, applied to a batch with probability ``p`` (default 1.0).

``output = PatchMix(alpha, patch_size, ...)(input)`` replaces a square patch in each image with the same region
of a randomly paired image of the batch, which can be the image itself.

Args:
    alpha: Hyperparameter for the Beta distribution used to generate the
        mixing parameter lambda.
    patch_size: The size of the square patch to mix.
    p: probability of applying the augmentation to the batch.
    same_on_batch: Apply the same transformation across the batch.
    keepdim: Whether to keep the output shape the same as input ``True``
        or broadcast it to the batch form ``False``.

Convention:
    - ``patch_size`` is the side length in pixels of a square patch and must not exceed ``min(H, W)``; a larger
      value, such as the default ``16`` on a smaller image, raises ``ValueError`` when parameters are drawn,
      whatever the gate. Each output sample copies that square from its paired input, ``_params["mix_pairs"]``,
      at the same sampled ``(x, y)`` top-left corner, ``_params["patch_coords"]``. The sampled ``lam`` is
      stored but blends nothing.
    - ``p`` is a batch-wide gate. ``same_on_batch=True`` shares the patch corner, not the pairing. Only image
      input is implemented.

.. image:: _static/img/PatchMix.png

See the Convention block on :class:`~kornia.augmentation.MixAugmentationBaseV2`.

Implementation for `CutMix: Regularization Strategy to Train Strong
Classifiers with Localizable Features` :cite:`yun2019cutmix`.

See Also:
    - :class:`RandomCutMixV2`: CutMix with paired labels and a sampled rectangle.

Examples:
    >>> aug = PatchMix(alpha=1.0, patch_size=4)
    >>> x = torch.rand(2, 3, 32, 32)
    >>> out = aug(x)
    >>> out.shape
    torch.Size([2, 3, 32, 32])
c                ó|   <€ V ^8„  d   QhRS[ RS[RS[ RS[RS[RS[S[S[S[S[S[3,          ,          ,          RR/# )	é   ÚalphaÚ
patch_sizeÚpÚsame_on_batchÚkeepdimÚ	data_keysÚreturnN)ÚfloatÚintÚboolr   r   r   Ústrr
   )ÚformatÚ__classdict__s   "€Ú`C:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\augmentation\_2d\mix\patchmix.pyÚ__annotate__ÚPatchMix.__annotate__E   sp   ø€ ÷ Kñ KáðKñ ðKñ ð	Kñ
 ðKñ ðKñ ™D¡¡s©C±Ð'8Õ!9Õ:Õ;ðKð 
ñKó    c                ó|   <€ \         SV `  R W4WVR7       Wn        W n        \        P
                  ! WV4      V n        R# )ç      ð?)r   Úp_batchr   r   r   N)ÚsuperÚ__init__r   r   ÚrgÚPatchMixGeneratorÚ_param_generator)Úselfr   r   r   r   r   r   Ú	__class__s   &&&&&&&€r   r$   ÚPatchMix.__init__E   s9   ø€ ô 	‰Ñ˜3¨ÐPWÐÔmØŒ
Ø$ŒÜ "× 4Ò 4°UÈÓ JˆÖr   c                ód   <€ V ^8„  d   QhRS[ P                  RS[S[S[ P                  3,          /# )r   Úbatch_shaper   )ÚtorchÚSizer   r   ÚTensor)r   r   s   "€r   r   r   S   s1   ø€ ÷ Fñ F©u¯z©zð F¹dÁ3ÉÏÉÐCTÕ>Uñ Fr   c                ó8   € V P                  WP                  4      # )N)r'   r   )r(   r,   s   &&r   Úgenerate_parametersÚPatchMix.generate_parametersS   s   € Ø×$Ñ$ [×2DÑ2DÓEÐEr   c                óš   <€ V ^8„  d   QhRS[ P                  RS[S[S[ P                  3,          RS[S[S[3,          RS[ P                  /# )r   ÚinputÚparamsÚ
extra_argsr   )r-   r/   r   r   r   )r   r   s   "€r   r   r   V   sO   ø€ ÷ ñ Ù—\‘\ðÙ+/±±U·\±\Ð0AÕ+BðÙPTÑUXÑZ]ÐU]ÕP^ðá	�‰ñr   c           	     óè  € VP                   w  p  pVR ,          P                  4       pVR,          P                  4       pVP                  4       p\        V4       F“  p	\	        Wy,          ^ ,          4      \	        Wy,          ^,          4      rºVWi,          RW»V P
                  ,           1WªV P
                  ,           13,          W‰RW»V P
                  ,           1WªV P
                  ,           13&   K•  	  V# )Ú	mix_pairsÚpatch_coords:NNN)ÚshapeÚtolistÚcloneÚranger   r   )r(   r4   r5   r6   ÚBÚ_Úidxr9   ÚoutÚiÚxÚys   &&&&        r   Úapply_transformÚPatchMix.apply_transformV   sÑ   € ð —[‘[‰
ˆˆ1ˆa�ð �[Õ!×(Ñ(Ó*ˆØ˜nÕ-×4Ñ4Ó6ˆà�k‰k‹mˆÜ�q–ˆAÜ�|• qÕ)Ó*¬C°µÀÕ0BÓ,CˆqØJOØ•˜˜1 4§?¡?Õ2Ð2°A¸D¿O¹OÕ8KÐ4KÐKõKˆC�1�a˜dŸo™oÕ-Ð-¨q°t·±Õ3FÐ/FÐFÓGñ ð ˆ
r   )r'   r   r   )r!   é   r!   FFN)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r$   r1   rE   Ú__static_attributes__Ú__classdictcell__Ú__classcell__)r)   r   s   @@r   r   r      s2   ù‡ € ñ'÷RKõ K÷Fð F÷÷ ð r   r   )Útypingr   r   r   r   r   r-   Úkornia.augmentationr   r%   Ú kornia.augmentation._2d.mix.baser	   Úkornia.constantsr
   r   © r   r   Ú<module>rU      s(   ð÷$ 4Õ 3ã å 6Ý BÝ $ôKÐ$ö Kr   