66from torch import Generator as Generator , Tensor as Tensor
77from torch import default_generator as default_generator , randperm as randperm
88from torch .utils .data .datapipes ._typing import _DataPipeMeta
9- from typing import Any , Callable , Dict , List , Optional , TypeVar
10- from torch .utils .data import DataChunk , Dataset , IterableDataset
9+ from typing import Any , Callable , Dict , Generic , Iterator , List , Optional , TypeVar
10+ from torch .utils .data import Dataset , IterableDataset
1111
1212T_co = TypeVar ('T_co' , covariant = True )
1313T = TypeVar ('T' )
@@ -32,6 +32,7 @@ class MapDataPipe(Dataset[T_co], metaclass=_DataPipeMeta):
3232 # Functional form of 'ZipperMapDataPipe'
3333 def zip (self , * datapipes : MapDataPipe [T_co ]) -> MapDataPipe : ...
3434
35+
3536class IterDataPipe (IterableDataset [T_co ], metaclass = _DataPipeMeta ):
3637 functions : Dict [str , Callable ] = ...
3738 reduce_ex_hook : Optional [Callable ] = ...
@@ -76,5 +77,24 @@ class IterDataPipe(IterableDataset[T_co], metaclass=_DataPipeMeta):
7677 # Functional form of 'ZipperIterDataPipe'
7778 def zip (self , * datapipes : IterDataPipe ) -> IterDataPipe : ...
7879
80+
7981class DFIterDataPipe (IterDataPipe ):
8082 def _is_dfpipe (self ): ...
83+
84+
85+ class DataChunk (list , Generic [T ]):
86+ def __init__ (self , items ):
87+ super ().__init__ (items )
88+ self .items = items
89+
90+ def as_str (self , indent = '' ):
91+ res = indent + "[" + ", " .join (str (i ) for i in iter (self )) + "]"
92+ return res
93+
94+ def __iter__ (self ) -> Iterator [T ]:
95+ for i in super ().__iter__ ():
96+ yield i
97+
98+ def raw_iterator (self ) -> T : # type: ignore[misc]
99+ for i in self .items :
100+ yield i
0 commit comments