
    ΅i?              	           S SK Jr  S SKJr  S SKJr  S SKJr  SS/r\" SSS	9r	\" S
5       " S S\5      5       r
\" S5       " S S\\\	S4      5      5       rg)    )Sized)TypeVar)functional_datapipe)MapDataPipeConcaterMapDataPipeZipperMapDataPipe_T_coT)	covariantconcatc                   X    \ rS rSr% Sr\\   \S'   S\SS4S jrS\	4S jr
S\4S jrS	rg)
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                     [        U5      S:X  a  [        S5      e[        S U 5       5      (       d  [        S5      e[        S U 5       5      (       d  [        S5      eXl        g )Nr   /Expected at least one DataPipe, but got nothingc              3   B   #    U  H  n[        U[        5      v   M     g 7fN
isinstancer   .0dps     b/home/james-whalen/.local/lib/python3.13/site-packages/torch/utils/data/datapipes/map/combining.py	<genexpr>/ConcaterMapDataPipe.__init__.<locals>.<genexpr>+        C2:b+..   'Expected all inputs to be `MapDataPipe`c              3   B   #    U  H  n[        U[        5      v   M     g 7fr   r   r   r   s     r   r   r   -        =9R:b%((9r   !Expected all inputs to be `Sized`len
ValueErrorall	TypeErrorr   selfr   s     r   __init__ConcaterMapDataPipe.__init__(   Y    y>QNOOCCCCEFF=9===?@@"    c                     SnU R                    H+  nX-
  [        U5      :  a	  X1U-
     s  $ U[        U5      -  nM-     [        SU S35      e)Nr   Index z is out of range.)r   r$   
IndexError)r)   indexoffsetr   s       r   __getitem__ConcaterMapDataPipe.__getitem__1   sW    ..B~B'&.)) #b'! ! 6%(9:;;r-   c                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  n[        U5      v   M     g 7fr   r$   r   s     r   r   .ConcaterMapDataPipe.__len__.<locals>.<genexpr>>        4^r3r77^   )sumr   r)   s    r   __len__ConcaterMapDataPipe.__len__<       4T^^444r-   r   )__name__
__module____qualname____firstlineno____doc__tupler   __annotations__r*   r	   r3   intr=   __static_attributes__ r-   r   r   r      s?    , [!!#; #4 #	<E 	<5 5r-   zipc                   r    \ rS rSr% Sr\\\   S4   \S'   S\\   SS4S jr	S\\S4   4S jr
S\4S	 jrS
rg)r   A   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                     [        U5      S:X  a  [        S5      e[        S U 5       5      (       d  [        S5      e[        S U 5       5      (       d  [        S5      eXl        g )Nr   r   c              3   B   #    U  H  n[        U[        5      v   M     g 7fr   r   r   s     r   r   -ZipperMapDataPipe.__init__.<locals>.<genexpr>Z   r   r   r   c              3   B   #    U  H  n[        U[        5      v   M     g 7fr   r    r   s     r   r   rP   \   r!   r   r"   r#   r(   s     r   r*   ZipperMapDataPipe.__init__W   r,   r-   c           	          / nU R                    H  n UR                  X1   5        M     [        U5      $ ! [         a  n[        SU SU S35      UeS nAff = f)Nr/   z3 is out of range for one of the input MapDataPipes .)r   appendr0   rF   )r)   r1   resr   es        r   r3   ZipperMapDataPipe.__getitem__`   sl    ..B

29% ! Sz	   UG#VWYVZZ[\s   5
AAAc                 :    [        S U R                   5       5      $ )Nc              3   8   #    U  H  n[        U5      v   M     g 7fr   r7   r   s     r   r   ,ZipperMapDataPipe.__len__.<locals>.<genexpr>m   r9   r:   )minr   r<   s    r   r=   ZipperMapDataPipe.__len__k   r?   r-   r@   )rA   rB   rC   rD   rE   rF   r   r	   rG   r*   r3   rH   r=   rI   rJ   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   rF   r   rJ   r-   r   <module>rc      sy    !  E ; !"5
64( X/5+ /5 /5d U+5E%*$56 +5 +5r-   