MapToIterConverter¶
- class torchdata.datapipes.iter.MapToIterConverter(datapipe: MapDataPipe, indices: Optional[List] = None)¶
Convert a
MapDataPipe
to anIterDataPipe
(functional name:to_iter_datapipe
). It usesindices
to iterate through theMapDataPipe
, defaults torange(len(mapdatapipe))
if not given.For the opposite converter, use
IterToMapConverter
.- Parameters:
datapipe – source MapDataPipe with data
indices – optional list of indices that will dictate how the datapipe will be iterated over
Example
>>> from torchdata.datapipes.map import SequenceWrapper >>> source_dp = SequenceWrapper(range(10)) >>> iter_dp = source_dp.to_iter_datapipe() >>> list(iter_dp) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> source_dp2 = SequenceWrapper({'a': 1, 'b': 2, 'c': 3}) >>> iter_dp2 = source_dp2.to_iter_datapipe(indices=['a', 'b', 'c']) >>> list(iter_dp2) [1, 2, 3]