o
    oi                     @   sr   d dl mZmZmZmZmZmZ d dlZd dlm	Z
 d dlmZ d dlmZ d dlmZ dgZG dd deZdS )	    )AnyDictListOptionalTupleUnionN)random_generator)MixAugmentationBaseV2)DataKey)TensorRandomJigsawc                       s   e Zd ZdZ						ddeeef deeee	ee
f   d	ed
edededdf fddZ	ddedee	ef deee	ef  defddZ  ZS )r   a{  RandomJigsaw augmentation.

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

    Make Jigsaw puzzles for each image individually. To mix with different images in a
    batch, referring to :class:`kornia.augmentation.RandomMosic`.

    Args:
        grid: the Jigsaw puzzle grid. e.g. (2, 2) means
            each output will mix image patches in a 2x2 grid.
        ensure_perm: to ensure the nonidentical patch permutation generation against
            the original one.
        data_keys: the input type sequential for applying augmentations.
            Accepts "input", "image", "mask", "bbox", "bbox_xyxy", "bbox_xywh", "keypoints",
            "class", "label".
        p: probability of applying the transformation for the whole 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``.

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

       r   N      ?FTgrid	data_keyspsame_on_batchkeepdimensure_permreturnc                    s2   t  j|d|||d t||| _d|i| _d S )Ng      ?)r   p_batchr   r   r   r   )super__init__rgJigsawGenerator_param_generatorflags)selfr   r   r   r   r   r   	__class__ V/home/ubuntu/.local/lib/python3.10/site-packages/kornia/augmentation/_2d/mix/jigsaw.pyr   <   s   	zRandomJigsaw.__init__inputparamsmaybe_flagsc                 C   sD  |d }|dk}||   }|j\}}}}	|d }
|jd | jd d  |jd | jd d  }}|d	||d
||||d||ddd	d
d|d||}|
tjd||
jdd d d f |
jd   	d}
|d d |
d d d d f }|d|| jd d ||ddd	dd
d||	|ddd
d	ddd	d
}|S )N
batch_probr   permutationr   r            r   )device)
cloneshaper   unfoldreshapepermutetorcharanger-   view)r   r#   r$   r%   r&   to_applybchwpermpiece_size_hpiece_size_wr!   r!   r"   apply_transformI   s*   2
2zRandomJigsaw.apply_transform)r   Nr   FFT)N)__name__
__module____qualname____doc__r   intr   r   r   strr
   floatboolr   r   r   r   r>   __classcell__r!   r!   r   r"   r      sB    

)typingr   r   r   r   r   r   r3   kornia.augmentationr   r    kornia.augmentation._2d.mix.baser	   kornia.constantsr
   kornia.corer   __all__r   r!   r!   r!   r"   <module>   s    