+
    úäûjÿ  ã                   óz   € ^ RI Ht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IHt R.t ! R R]4      tR# )	é    )ÚAnyÚDictÚListÚOptionalÚTupleÚUnionN)Úrandom_generator)ÚMixAugmentationBaseV2)ÚDataKey)Ú_to_device_nonblockingÚRandomJigsawc                   ó€   a a€ ] tR t^t oRtRV3R lV 3R llltRRRR/V3R lV 3R	 llltRV3R
 lR lltRtVt	V ;t
# )r   aá  Shuffle the tiles of each image like a jigsaw puzzle, applied per sample with probability ``p`` (default 0.5).

``output = RandomJigsaw(grid, ...)(input)`` rearranges the grid cells of each selected image.

Args:
    grid: the Jigsaw puzzle grid. e.g. (2, 2) means
        each output will mix image patches in a 2x2 grid.
    ensure_perm: reject the image-preserving permutation ``arange(N).view(rows, columns).T.flatten()`` when
        drawing, so a selected sample is never returned unchanged. For a single-row or single-column grid that
        permutation is ``[0, ..., N - 1]``; see the Convention block. A ``1 x 1`` grid has no other
        permutation, so it raises ``ValueError`` unless ``ensure_perm=False``.
    data_keys: the input type sequential for applying augmentations. Only "input" and "image" are
        implemented; see the Convention block.
    p: probability of applying the transformation to each sample.
    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:
    - ``grid=(rows, columns)`` partitions each image independently. Both image dimensions must be divisible by
      their grid entries, otherwise ``RuntimeError`` is raised whatever the gate. An entry's position selects
      the destination cell in column-major order, while its value indexes the source patch in row-major order,
      so the identity permutation reproduces the image only on a single-row or single-column grid (on a square
      grid it transposes the patches). The image-preserving permutation is
      ``arange(N).view(rows, columns).T.flatten()``, ``[0, 2, 1, 3]`` for a ``2 x 2`` grid.
    - ``p`` is a per-sample gate; ``same_on_batch=True`` shares one gate draw and one permutation. Only image
      input is implemented.

.. image:: _static/img/RandomJigsaw.png

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

See Also:
    - :class:`RandomMosaic`: composes a crop from multiple images in the batch.

Examples:
    >>> jigsaw = RandomJigsaw((4, 4))
    >>> input = torch.randn(8, 3, 256, 256)
    >>> out = jigsaw(input)
    >>> out.shape
    torch.Size([8, 3, 256, 256])

NTc                ó’   <€ V ^8„  d   QhRS[ S[S[3,          RS[S[S[S[S[S[3,          ,          ,          RS[RS[RS[RS[RR/# )	é   ÚgridÚ	data_keysÚpÚsame_on_batchÚkeepdimÚensure_permÚreturnN)	r   Úintr   r   r   Ústrr   ÚfloatÚbool)ÚformatÚ__classdict__s   "€Ú^C:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\augmentation\_2d\mix\jigsaw.pyÚ__annotate__ÚRandomJigsaw.__annotate__K   so   ø€ ÷ $ñ $á‘C™�H�oð$ñ ™D¡¡s©C±Ð'8Õ!9Õ:Õ;ð$ñ ð	$ñ
 ð$ñ ð$ñ ð$ð 
ñ$ó    c                óv   <€ \         SV `  VR WEVR7       \        P                  ! W4      V n        RV/V n        R# )g      ð?)r   Úp_batchr   r   r   r   N)ÚsuperÚ__init__ÚrgÚJigsawGeneratorÚ_param_generatorÚflags)Úselfr   r   r   r   r   r   Ú	__class__s   &&&&&&&€r   r%   ÚRandomJigsaw.__init__K   s:   ø€ ô 	‰Ñ˜1 c¸ÐclÐÔmÜ "× 2Ò 2°4Ó EˆÔØ˜d�^ˆŽ
r!   ÚshapeÚmatch_channelc                ó~   <€ V ^8„  d   QhRS[ P                  RS[S[ P                  ,          RS[RS[ P                  /# )r   Úinputr-   r.   r   )ÚtorchÚTensorr   r   )r   r   s   "€r   r   r    X   s>   ø€ ÷ ñ Ù—\‘\ðÙ-5±e·l±lÕ-CðÙ[_ðá	�‰ñr!   c               ó,  <€ \         SV `  WVR 7      pVP                  RR w  rEW@P                  R,          ^ ,          ,          '       g'   WPP                  R,          ^,          ,          '       d%   \	        RWE3 RV P                  R,           R24      hV# ))r-   r.   Nr   zInput height and width z must be divisible by grid Ú.éþÿÿÿ)r$   Útransform_tensorr-   r)   ÚRuntimeError)r*   r0   r-   r.   ÚhÚwr+   s   &&$$  €r   r6   ÚRandomJigsaw.transform_tensorX   sŠ   ø€ ô ‘Ñ(¨È=Ð(ÓYˆØ�{‰{˜2˜3Ð‰ˆØ�z‰z˜&Õ! !Õ$×$Ô$¨¯J©J°vÕ,>¸qÕ,A×(AÔ(AÜÐ!8¸!¸¸Ð@[Ð\`×\fÑ\fÐgmÕ\nÐ[oÐopÐqÓrÐrØˆr!   c          	      óª   <€ V ^8„  d   QhRS[ P                  RS[S[S[ P                  3,          RS[S[S[S[3,          ,          RS[ P                  /# )r   r0   ÚparamsÚmaybe_flagsr   )r1   r2   r   r   r   r   )r   r   s   "€r   r   r    a   sU   ø€ ÷ 
ñ 
Ù—\‘\ð
Ù+/±±U·\±\Ð0AÕ+Bð
ÙQYÑZ^Ñ_bÑdgÐ_gÕZhÕQið
á	�‰ñ
r!   c                óz  € VP                   w  rErgVR ,          pVP                   R,          V P                  R,          ^ ,          ,          VP                   R,          V P                  R,          ^,          ,          r©VP                  ^W™4      P                  ^Wª4      P                  WERWš4      P	                  ^^ ^^^4      P                  VRWš4      pV\
        P                  ! ^ WHP                  R7      R,          VP                   ^,          ,          ,           P                  R4      pVR\        W�P                  4      RR3,          pVP                  RW@P                  R,          ^,          Wj4      P	                  ^ ^^^^4      P                  RWGV4      P	                  ^ ^^^4      P	                  ^^ ^^4      # )Úpermutationr   )ÚdeviceºNNNr5   éÿÿÿÿ)rA   N)
r-   r)   ÚunfoldÚreshapeÚpermuter1   Úaranger@   Úviewr   )r*   r0   r<   r=   ÚbÚcr8   r9   ÚpermÚpiece_size_hÚpiece_size_ws   &&&&       r   Úapply_transformÚRandomJigsaw.apply_transforma   sg  € ð
 —[‘[‰
ˆˆaØ�mÕ$ˆØ%*§[¡[°¥_¸¿
¹
À6Õ8JÈ1Õ8MÕ%MÈuÏ{É{Ð[]ÍÐbf×blÑblÐmsÕbtÐuvÕbwÕOw�lð �L‰L˜˜LÓ7ß‰V�A�|Ó2ß‰W�Q˜2˜|Ó:ß‰W�Q˜˜1˜a Ó#ß‰W�Q˜˜LÓ7ð 	ð ”u—|’| A q·±Ô=¸gÕFÈÏÉÐTUÍÕVÕV×\Ñ\Ð]_Ó`ˆØ�aÔ/°·l±lÓCÀQÈÐIÕJˆà�M‰M˜"˜a§¡¨FÕ!3°AÕ!6¸ÓHß‰W�Q˜˜1˜a Ó#ß‰W�R˜˜qÓ!ß‰W�Q˜˜1˜aÓ ß‰W�Q˜˜1˜aÓ ð	
r!   )r(   r)   ))é   rO   Ng      à?FFT)N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r%   r6   rM   Ú__static_attributes__Ú__classdictcell__Ú__classcell__)r+   r   s   @@r   r   r      s>   ù‡ € ñ*÷X$õ $ðØFJðØbf÷õ ÷
÷ 
ò 
r!   )Útypingr   r   r   r   r   r   r1   Úkornia.augmentationr	   r&   Ú kornia.augmentation._2d.mix.baser
   Úkornia.constantsr   Úkornia.core.utilsr   Ú__all__r   © r!   r   Ú<module>r_      s3   ð÷$ ;× :ã å 6Ý BÝ $Ý 4àÐ
€ô[
Ð(ö [
r!   