o
    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dededee dee fddZdedefddZddedee defddZdededee defddZdS )    N)
Collection)OptionalUnion)dill_available)IterDataPipeMapDataPipetraversetraverse_dpsDataPipeGraphc                   C   s   dS )NSTUB r   r   r   j/var/www/html/construction_image-detection-poc/venv/lib/python3.10/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}	zQ|	D ]}
|
| |r<|
	| q.z|
 W n tjttfy[   t rX|
 n Y nw W |	D ]}
|
d  |rm|
	d  q_t r{ddlm} |d S |	D ]}
|
d  |r|
	d  qt rddlm} |d w w )	Nr   )Picklerc                 S   s   d }t | tr i }|  D ]\}}t |tttfr|||< q|S t | ttfr=g }| D ]}t |tttfr:|| q+|S t | tttfrG| }|S N)	
isinstancedictitemsr   r   r   tuplelistappend)	ori_statestatekvr   r   r   getstate_hook'   s$   

z0_list_connected_datapipes.<locals>.getstate_hookc                    s8   | ks
t |  v rt|   t |  tdfS )Nr   )idNotImplementedErrorr   addr   )objr   captured_connectionsr   r   r   reduce_hook7   s
   
z._list_connected_datapipes.<locals>.reduce_hook)extendF)ioBytesIOpickler   r   dillr   r   set_reduce_ex_hookset_getstate_hookdumpPickleErrorAttributeError	TypeErrorr'   )r   r   r   fpdill_Picklerdr   r&   datapipe_classesclsdill_extendr   r$   r   _list_connected_datapipes   sZ   
	






r9   datapipec                 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)r:   r   r   r   r   r	   Z   s   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FutureWarningr;   r<   )r:   r   msgr   r   r   r   r   l   s   c                 C   s   t | ttfstdt|  dt| }||v ri S || t| || }|| i fi}|D ]}|| d 	t
|||  q0|S )Nz.Expected `IterDataPipe` or `MapDataPipe`, but z	 is found   )r   r   r   RuntimeErrortyper    r"   r9   copyupdater<   )r:   r   r   dp_idr   r5   itemr   r   r   r<      s   
 r<   r   )r(   r*   r=   collections.abcr   typingr   r   torch.utils._import_utilsr   #torch.utils.data.datapipes.datapiper   r   __all__DataPiper   intr   r
   r   boolr;   r   r9   r	   r   r<   r   r   r   r   <module>   s>   
C"