o
    wZhs                     @   s   d dl mZ d dlmZ d dlmZ d dlmZ ddgZeddd	Z	ed
G dd deZ
edG dd deee	df  ZdS )    )Sized)TypeVar)functional_datapipe)MapDataPipeConcaterMapDataPipeZipperMapDataPipe_T_coT)	covariantconcatc                   @   sH   e Zd ZU dZee ed< defddZdefddZ	de
fdd	Zd
S )r   a  
    Concatenate multiple Map DataPipes (functional name: ``concat``).

    The new index of is the cumulative sum of source DataPipes.
    For example, if there are 2 source DataPipes both with length 5,
    index 0 to 4 of the resulting `ConcatMapDataPipe` would refer to
    elements of the first DataPipe, and 5 to 9 would refer to elements
    of the second DataPipe.

    Args:
        datapipes: Map DataPipes being concatenated

    Example:
        >>> # xdoctest: +SKIP
        >>> from torchdata.datapipes.map import SequenceWrapper
        >>> dp1 = SequenceWrapper(range(3))
        >>> dp2 = SequenceWrapper(range(3))
        >>> concat_dp = dp1.concat(dp2)
        >>> list(concat_dp)
        [0, 1, 2, 0, 1, 2]
    	datapipesc                 G   R   t |dkr
tdtdd |D stdtdd |D s$td|| _d S )Nr   /Expected at least one DataPipe, but got nothingc                 s       | ]}t |tV  qd S N
isinstancer   .0dp r   W/var/www/auris/lib/python3.10/site-packages/torch/utils/data/datapipes/map/combining.py	<genexpr>+       z/ConcaterMapDataPipe.__init__.<locals>.<genexpr>'Expected all inputs to be `MapDataPipe`c                 s   r   r   r   r   r   r   r   r   r   -   r   !Expected all inputs to be `Sized`len
ValueErrorall	TypeErrorr   selfr   r   r   r   __init__(      
zConcaterMapDataPipe.__init__returnc                 C   sL   d}| j D ]}|| t|k r|||    S |t|7 }qtd| d)Nr   Index z is out of range.)r   r   
IndexError)r"   indexoffsetr   r   r   r   __getitem__1   s   
zConcaterMapDataPipe.__getitem__c                 C      t dd | jD S )Nc                 s       | ]}t |V  qd S r   r   r   r   r   r   r   ;       z.ConcaterMapDataPipe.__len__.<locals>.<genexpr>)sumr   r"   r   r   r   __len__:      zConcaterMapDataPipe.__len__N)__name__
__module____qualname____doc__tupler   __annotations__r#   r   r*   intr1   r   r   r   r   r      s   
 		zipc                   @   s`   e Zd ZU dZeee df ed< dee ddfddZdeedf fdd	Z	de
fd
dZdS )r   a%  
    Aggregates elements into a tuple from each of the input DataPipes (functional name: ``zip``).

    This MataPipe is out of bound as soon as the shortest input DataPipe is exhausted.

    Args:
        *datapipes: Map DataPipes being aggregated

    Example:
        >>> # xdoctest: +SKIP
        >>> from torchdata.datapipes.map import SequenceWrapper
        >>> dp1 = SequenceWrapper(range(3))
        >>> dp2 = SequenceWrapper(range(10, 13))
        >>> zip_dp = dp1.zip(dp2)
        >>> list(zip_dp)
        [(0, 10), (1, 11), (2, 12)]
    .r   r%   Nc                 G   r   )Nr   r   c                 s   r   r   r   r   r   r   r   r   W   r   z-ZipperMapDataPipe.__init__.<locals>.<genexpr>r   c                 s   r   r   r   r   r   r   r   r   Y   r   r   r   r!   r   r   r   r#   T   r$   zZipperMapDataPipe.__init__c                 C   sZ   g }| j D ]#}z	|||  W q ty( } ztd| d| d|d }~ww t|S )Nr&   z3 is out of range for one of the input MapDataPipes .)r   appendr'   r7   )r"   r(   resr   er   r   r   r*   ]   s   
zZipperMapDataPipe.__getitem__c                 C   r+   )Nc                 s   r,   r   r-   r   r   r   r   r   i   r.   z,ZipperMapDataPipe.__len__.<locals>.<genexpr>)minr   r0   r   r   r   r1   h   r2   zZipperMapDataPipe.__len__)r3   r4   r5   r6   r7   r   r   r8   r#   r*   r9   r1   r   r   r   r   r   >   s   
 	.N)collections.abcr   typingr   Z%torch.utils.data.datapipes._decoratorr   Z#torch.utils.data.datapipes.datapiper   __all__r   r   r7   r   r   r   r   r   <module>   s   /"