o
    wZŽh'  ã                   @   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)ÚMapDataPipeÚSequenceWrapperMapDataPipec                   @   s*   e Zd ZdZd
dd„Zdd„ Zdd„ Zd	S )r   aö  
    Wraps a sequence object into a MapDataPipe.

    Args:
        sequence: Sequence object to be wrapped into an MapDataPipe
        deepcopy: Option to deepcopy input sequence object

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

    Example:
        >>> # xdoctest: +SKIP
        >>> from torchdata.datapipes.map import SequenceWrapper
        >>> dp = SequenceWrapper(range(10))
        >>> list(dp)
        [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
        >>> dp = SequenceWrapper({'a': 100, 'b': 200, 'c': 300, 'd': 400})
        >>> dp['a']
        100
    Tc                 C   sF   |rz	t  |¡| _W d S  ty   t d¡ || _Y d S w || _d S )NzkThe input sequence can not be deepcopied, please be aware of in-place modification would affect source data)ÚcopyÚdeepcopyÚsequenceÚ	TypeErrorÚwarningsÚwarn)Úselfr   r   © r   úS/var/www/auris/lib/python3.10/site-packages/torch/utils/data/datapipes/map/utils.pyÚ__init__$   s   ÿû
z#SequenceWrapperMapDataPipe.__init__c                 C   s
   | j | S ©N)r   )r
   Úindexr   r   r   Ú__getitem__1   ó   
z&SequenceWrapperMapDataPipe.__getitem__c                 C   s
   t | jƒS r   )Úlenr   )r
   r   r   r   Ú__len__4   r   z"SequenceWrapperMapDataPipe.__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
   