a
    h                     @   s   d dl Z d dlZd dlZd dlmZ d dlmZmZ d dlm	Z	 d dl
mZmZ ddgZeeef Zeeeedf f Zd	d
 Zeeee ee dddZeedddZdeee edddZeeee edddZdS )    N)
Collection)OptionalUnion)dill_available)IterDataPipeMapDataPipetraversetraverse_dpsDataPipeGraphc                   C   s   dS )NZSTUB r   r   r   D/var/www/auris/lib/python3.9/site-packages/torch/utils/data/graph.py_stub_unpickler   s    r   )scan_objonly_datapipecachereturnc              
      s<  t  }t|}t r.ddlm} ||}nd }g dd } fdd}ttf}	z|	D ]}
|
| |r\|
	| q\z|
 W n. tjttfy   t r|
 n Y n0 W |	D ]}
|
d  |r|
	d  qt rddlm} |d n@|	D ]}
|
d  |r|
	d  qt r6ddlm} |d 0 S )	Nr   )Picklerc                 S   s   d }t | tr>i }|  D ] \}}t |tttfr|||< qnLt | ttfrvg }| D ]}t |tttfrT|| qTnt | tttfr| }|S )N)	
isinstancedictitemsr   r   r   tuplelistappend)Z	ori_statestatekvr   r   r   getstate_hook'   s    
z0_list_connected_datapipes.<locals>.getstate_hookc                    s>   | kst |  v rtn |   t |  tdfS d S )Nr   )idNotImplementedErrorr   addr   )objr   Zcaptured_connectionsr   r   r   reduce_hook7   s
    
z._list_connected_datapipes.<locals>.reduce_hook)extendF)ioBytesIOpickler   r   Zdillr   r   Zset_reduce_ex_hookZset_getstate_hookdumpPickleErrorAttributeError	TypeErrorr#   )r   r   r   fpZdill_Picklerdr   r"   Zdatapipe_classesclsZdill_extendr   r!   r   _list_connected_datapipes   sL    
	





r/   )datapiper   c                 C   s   t  }t| d|dS )a  
    Traverse the DataPipes and their attributes to extract the DataPipe graph.

    This only looks into the attribute from each DataPipe that is either a
    DataPipe and a Python collection object such as ``list``, ``tuple``,
    ``set`` and ``dict``.

    Args:
        datapipe: the end DataPipe of the graph
    Returns:
        A graph represented as a nested dictionary, where keys are ids of DataPipe instances
        and values are tuples of DataPipe instance and the sub-graph
    T)r   r   )set_traverse_helper)r0   r   r   r   r   r	   Z   s    )r0   r   r   c                 C   s:   d}|s|d7 }t |t |du r(d}t }t| ||S )a6  
    Traverse the DataPipes and their attributes to extract the DataPipe graph.

    [Deprecated]
    When ``only_dataPipe`` is specified as ``True``, it would only look into the
    attribute from each DataPipe that is either a DataPipe and a Python collection object
    such as ``list``, ``tuple``, ``set`` and ``dict``.

    Note:
        This function is deprecated. Please use `traverse_dps` instead.

    Args:
        datapipe: the end DataPipe of the graph
        only_datapipe: If ``False`` (default), all attributes of each DataPipe are traversed.
          This argument is deprecating and will be removed after the next release.
    Returns:
        A graph represented as a nested dictionary, where keys are ids of DataPipe instances
        and values are tuples of DataPipe instance and the sub-graph
    zV`traverse` function and will be removed after 1.13. Please use `traverse_dps` instead.zM And, the behavior will be changed to the equivalent of `only_datapipe=True`.NF)warningswarnFutureWarningr1   r2   )r0   r   msgr   r   r   r   r   l   s    )r0   r   r   r   c                 C   s   t | ttfs"tdt|  dt| }||v r6i S || t| || }|| i fi}|D ]"}|| d 	t
|||  q`|S )Nz.Expected `IterDataPipe` or `MapDataPipe`, but z	 is found   )r   r   r   RuntimeErrortyper   r   r/   copyupdater2   )r0   r   r   Zdp_idr   r-   itemr   r   r   r2      s    
 r2   )N)r$   r&   r3   collections.abcr   typingr   r   Ztorch.utils._import_utilsr   Z#torch.utils.data.datapipes.datapiper   r   __all__ZDataPiper   intr   r
   r   boolr1   r   r/   r	   r   r2   r   r   r   r   <module>   s$   
C#
