
    sg_              	           d dl mZmZmZ d dlmZ d dl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)    )SizedTupleTypeVar)functional_datapipe)MapDataPipe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     [/var/www/html/venv/lib/python3.12/site-packages/torch/utils/data/datapipes/map/combining.py	<genexpr>z/ConcaterMapDataPipe.__init__.<locals>.<genexpr>*        C2:b+.C   '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>,        =R:b%(=r   !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__0   s^    .. 	"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>:        4r3r74   )sumr   r'   s    r   __len__zConcaterMapDataPipe.__len__9       4T^^444r*   N)__name__
__module____qualname____doc__r   r   __annotations__r(   r
   r1   intr9    r*   r   r   r      s8    , [!!#; #<E <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>V   r   r   r   c              3   <   K   | ]  }t        |t                y wr   r   r   s     r   r   z-ZipperMapDataPipe.__init__.<locals>.<genexpr>X   r   r   r    r!   r&   s     r   r(   zZipperMapDataPipe.__init__S   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__\   ss    .. 	B

2e9%	 Sz	   UG#VWYVZZ[\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>h   r5   r6   )minr   r8   s    r   r9   zZipperMapDataPipe.__len__g   r:   r*   )r;   r<   r=   r>   r   r   r
   r?   r(   r1   r@   r9   rA   r*   r   r	   r	   =   sW    $ [',--#;u#5 #$ #	E%*$5 	5 5r*   .N)typingr   r   r   %torch.utils.data.datapipes._decoratorr   #torch.utils.data.datapipes.datapiper   __all__r
   r   r	   rA   r*   r   <module>rT      sy    ( ( E ; !"5
64( X,5+ ,5 ,5^ U*5E%*$56 *5 *5r*   