
    ti?              	           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	      Z	 ed
       G d de             Z
 ed       G d deee	df                   Zy)    )Sized)TypeVar)functional_datapipe)MapDataPipeConcaterMapDataPipeZipperMapDataPipe_T_coT)	covariantconcatc                   J    e Zd ZU dZee   ed<   dedd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]
    	datapipesreturnNc                     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     n/home/ubuntu/crypto_trading_bot/.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==?@@"    c                     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__1   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__<       4T^^444r*   )__name__
__module____qualname____doc__tupler   __annotations__r(   r	   r0   intr8    r*   r   r   r      s?    , [!!#; #4 #	<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>Z   r   r   r   c              3   <   K   | ]  }t        |t                y wr   r   r   s     r   r   z-ZipperMapDataPipe.__init__.<locals>.<genexpr>\   r   r   r    r!   r&   s     r   r(   zZipperMapDataPipe.__init__W   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-   r>   )r'   r.   resr   es        r   r0   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   r3   r   s     r   r   z,ZipperMapDataPipe.__len__.<locals>.<genexpr>m   r4   r5   )minr   r7   s    r   r8   zZipperMapDataPipe.__len__k   r9   r*   )r:   r;   r<   r=   r>   r   r	   r?   r(   r0   r@   r8   rA   r*   r   r   r   A   sW    $ [',--#;u#5 #$ #	E%*$5 	5 5r*   .N)collections.abcr   typingr   %torch.utils.data.datapipes._decoratorr   #torch.utils.data.datapipes.datapiper   __all__r	   r   r>   r   rA   r*   r   <module>rT      sy    !  E ; !"5
64( X/5+ /5 /5d U+5E%*$56 +5 +5r*   