U
    <ºc  ã                   @   s6   d dl Z d dlZd dlmZ dgZG dd„ deƒZdS )é    N)ÚIterDataPipeÚIterableWrapperIterDataPipec                   @   s*   e Zd ZdZd
dd„Zdd„ Zdd„ Zd	S )r   añ  
    Wraps an iterable object to create an IterDataPipe.

    Args:
        iterable: Iterable object to be wrapped into an IterDataPipe
        deepcopy: Option to deepcopy input iterable object for each
            iterator. The copy is made when the first element is read in ``iter()``.

    .. note::
        If ``deepcopy`` is explicitly set to ``False``, users should ensure
        that the data pipeline doesn't contain any in-place operations over
        the iterable instance to prevent data inconsistency across iterations.

    Example:
        >>> # xdoctest: +SKIP
        >>> from torchdata.datapipes.iter import IterableWrapper
        >>> dp = IterableWrapper(range(10))
        >>> list(dp)
        [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    Tc                 C   s   || _ || _d S ©N)ÚiterableÚdeepcopy)Úselfr   r   © r   úI/tmp/pip-unpacked-wheel-gikjz4vx/torch/utils/data/datapipes/iter/utils.pyÚ__init__   s    z$IterableWrapperIterDataPipe.__init__c                 c   sP   | j }| jr<zt | j ¡}W n tk
r:   t d¡ Y nX |D ]
}|V  q@d S )NzlThe input iterable can not be deepcopied, please be aware of in-place modification would affect source data.)r   r   ÚcopyÚ	TypeErrorÚwarningsÚwarn)r   Zsource_dataÚdatar   r   r	   Ú__iter__!   s    ÿ
z$IterableWrapperIterDataPipe.__iter__c                 C   s
   t | jƒS r   )Úlenr   )r   r   r   r	   Ú__len__2   s    z#IterableWrapperIterDataPipe.__len__N)T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   r   r   r   r   r   r	   r      s   
)r   r   Z#torch.utils.data.datapipes.datapiper   Ú__all__r   r   r   r   r	   Ú<module>   s   