
    Phx              	           d dl mZ d dlmZ d dlmZmZmZ ddgZ edd      Z	 ed	       G d
 de             Z
 ed       G d deee	df                   Zy)    )functional_datapipe)MapDataPipe)SizedTupleTypeVarConcaterMapDataPipeZipperMapDataPipeT_coT)	covariantconcatc                   F    e Zd ZU dZee   ed<   defdZdefdZ	de
fdZy)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                     t        |      dk(  rt        d      t        d |D              st        d      t        d |D              st        d      || _        y )Nr   /Expected at least one DataPipe, but got nothingc              3   <   K   | ]  }t        |t                y wN
isinstancer   .0dps     sC:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\site-packages\torch/utils/data/datapipes/map/combining.py	<genexpr>z/ConcaterMapDataPipe.__init__.<locals>.<genexpr>'        C2:b+.   'Expected all inputs to be `MapDataPipe`c              3   <   K   | ]  }t        |t                y wr   r   r   r   s     r   r   z/ConcaterMapDataPipe.__init__.<locals>.<genexpr>)        =9R:b%(9r   !Expected all inputs to be `Sized`len
ValueErrorall	TypeErrorr   selfr   s     r   __init__zConcaterMapDataPipe.__init__$   U    y>QNOOCCCEFF=9==?@@"    returnc                     d}| j                   D ]+  }||z
  t        |      k  r
|||z
     c S |t        |      z  }- t        d| d      )Nr   Index z is out of range.)r   r"   
IndexError)r'   indexoffsetr   s       r   __getitem__zConcaterMapDataPipe.__getitem__-   sY    ..Bv~B'%&.))#b'!	 !
 6%(9:;;r*   c                 :    t        d | j                  D              S )Nc              3   2   K   | ]  }t        |        y wr   r"   r   s     r   r   z.ConcaterMapDataPipe.__len__.<locals>.<genexpr>7        4^r3r7^   )sumr   r'   s    r   __len__zConcaterMapDataPipe.__len__6       4T^^444r*   N)__name__
__module____qualname____doc__r   r   __annotations__r(   r
   r1   intr9    r*   r   r   r   
   s8    , [!!#; #<D <5 5r*   zipc                   d    e Zd ZU dZeee   df   ed<   dee   ddfdZdeedf   fdZ	de
fdZy)	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                     t        |      dk(  rt        d      t        d |D              st        d      t        d |D              st        d      || _        y )Nr   r   c              3   <   K   | ]  }t        |t                y wr   r   r   s     r   r   z-ZipperMapDataPipe.__init__.<locals>.<genexpr>S   r   r   r   c              3   <   K   | ]  }t        |t                y wr   r   r   s     r   r   z-ZipperMapDataPipe.__init__.<locals>.<genexpr>U   r   r   r    r!   r&   s     r   r(   zZipperMapDataPipe.__init__P   r)   r*   c           	          g }| j                   D ]  }	 |j                  ||           t        |      S # t        $ r}t        d| d| d      |d }~ww xY w)Nr-   z3 is out of range for one of the input MapDataPipes .)r   appendr.   tuple)r'   r/   resr   es        r   r1   zZipperMapDataPipe.__getitem__Y   sl    ..Br

2e9% !
 Sz  r 6%0cdfcggh!ijpqqrs   4	AAAc                 :    t        d | j                  D              S )Nc              3   2   K   | ]  }t        |        y wr   r4   r   s     r   r   z,ZipperMapDataPipe.__len__.<locals>.<genexpr>c   r5   r6   )minr   r8   s    r   r9   zZipperMapDataPipe.__len__b   r:   r*   )r;   r<   r=   r>   r   r   r
   r?   r(   r1   r@   r9   rA   r*   r   r	   r	   :   sW    $ [&+,,#;t#4 # #E$)$4 5 5r*   .N)%torch.utils.data.datapipes._decoratorr   #torch.utils.data.datapipes.datapiper   typingr   r   r   __all__r
   r   r	   rA   r*   r   <module>rT      sw    E ; ( ( "5
6v& X,5+ ,5 ,5^ U(5E$)$45 (5 (5r*   