o
    oi                     @   sX   d dl mZmZmZ d dlmZmZ ddlmZ G dd dej	Z
G dd dej	Zd	S )
    )ListTupleUnion)Tensornn   )AugmentationSequentialc                       sv   e Zd ZdZdeddf fddZdedefddZd	ee	e
 e	ee
  f dee	e
 e	ee
  f fd
dZ  ZS )ManyToManyAugmentationDispathera  Dispatches different augmentations to different inputs element-wisely.

    Args:
        augmentations: a list or a sequence of kornia AugmentationSequential modules.

    Examples:
        >>> import torch
        >>> input_1, input_2 = torch.randn(2, 3, 5, 6), torch.randn(2, 3, 5, 6)
        >>> mask_1, mask_2 = torch.ones(2, 3, 5, 6), torch.ones(2, 3, 5, 6)
        >>> aug_list = ManyToManyAugmentationDispather(
        ...     AugmentationSequential(
        ...         kornia.augmentation.ColorJiggle(0.1, 0.1, 0.1, 0.1, p=1.0),
        ...         kornia.augmentation.RandomAffine(360, p=1.0),
        ...         data_keys=["input", "mask",],
        ...     ),
        ...     AugmentationSequential(
        ...         kornia.augmentation.ColorJiggle(0.1, 0.1, 0.1, 0.1, p=1.0),
        ...         kornia.augmentation.RandomAffine(360, p=1.0),
        ...         data_keys=["input", "mask",],
        ...     )
        ... )
        >>> output = aug_list((input_1, mask_1), (input_2, mask_2))

    augmentationsreturnNc                    s   t    | j|  || _d S N)super__init___check_consistencyr
   )selfr
   	__class__ \/home/ubuntu/.local/lib/python3.10/site-packages/kornia/augmentation/container/dispatcher.pyr   3   s   


z(ManyToManyAugmentationDispather.__init__c                 G   s0   t |D ]\}}t|tstd| dqdS )N Please wrap your augmentations[`"`] with `AugmentationSequentials`.T)	enumerate
isinstancer   
ValueErrorr   r
   iaugr   r   r   r   8   s
   
z2ManyToManyAugmentationDispather._check_consistencyinputc                 G   s   dd t || jD S )Nc                 S   s   g | ]\}}|| qS r   r   ).0inpr   r   r   r   
<listcomp>?   s    z;ManyToManyAugmentationDispather.forward.<locals>.<listcomp>)zipr
   r   r   r   r   r   forward>   s   z'ManyToManyAugmentationDispather.forward)__name__
__module____qualname____doc__r   r   boolr   r   r   r   r   r#   __classcell__r   r   r   r   r	      s
    Br	   c                       sx   e Zd ZdZdddededdf fdd	Zdedefd
dZdee	e
e	 f deee	 ee
e	  f fddZ  ZS )ManyToOneAugmentationDispathera  Dispatches different augmentations to a single input and returns a list.

    Same `datakeys` must be applied across different augmentations. By default, with input
    (image, mask), the augmentations must not mess it as (mask, image) to avoid unexpected
    errors. This check can be cancelled with `strict=False` if needed.

    Args:
        augmentations: a list or a sequence of kornia AugmentationSequential modules.

    Examples:
        >>> import torch
        >>> input = torch.randn(2, 3, 5, 6)
        >>> mask = torch.ones(2, 3, 5, 6)
        >>> aug_list = ManyToOneAugmentationDispather(
        ...     AugmentationSequential(
        ...         kornia.augmentation.ColorJiggle(0.1, 0.1, 0.1, 0.1, p=1.0),
        ...         kornia.augmentation.RandomAffine(360, p=1.0),
        ...         data_keys=["input", "mask",],
        ...     ),
        ...     AugmentationSequential(
        ...         kornia.augmentation.ColorJiggle(0.1, 0.1, 0.1, 0.1, p=1.0),
        ...         kornia.augmentation.RandomAffine(360, p=1.0),
        ...         data_keys=["input", "mask",],
        ...     )
        ... )
        >>> output = aug_list(input, mask)

    T)strictr
   r+   r   Nc                   s$   t    || _| j|  || _d S r   )r   r   r+   r   r
   )r   r+   r
   r   r   r   r   `   s   


z'ManyToOneAugmentationDispather.__init__c                 G   s   t |D ];\}}t|tstd| d| jr?|dkr?|j||d  jkr?td|d  d| d|j d||d  j d	qd	S )
Nr   r   r   r   zDifferent `data_keys` between z and z elements, got .T)r   r   r   r   r+   	data_keysRuntimeErrorr   r   r   r   r   f   s   
"z1ManyToOneAugmentationDispather._check_consistencyr   c                    s    fdd| j D S )Nc                    s   g | ]}|  qS r   r   )r   r   r   r   r   r    r   s    z:ManyToOneAugmentationDispather.forward.<locals>.<listcomp>)r
   r"   r   r/   r   r#   q   s   z&ManyToOneAugmentationDispather.forward)r$   r%   r&   r'   r   r(   r   r   r   r   r   r   r#   r)   r   r   r   r   r*   B   s
     :r*   N)typingr   r   r   torchr   r   augmentr   Moduler	   r*   r   r   r   r   <module>   s
   )