a
    ==ic'  ã                   @   s„   d dl Z d dlZd dlmZ d dlmZ dZe ¡ add„ Z	dd„ Z
e jdd
d„ƒZe jddd„ƒZe jdd„ ƒZe jdd„ ƒZdS )é    N)Ú
basestring)Ú
caffe2_pb2ú/c                   C   s   t tdƒsdt_tjS )NÚ	namescopeÚ )ÚhasattrÚ_threadlocal_scoper   © r	   r	   úd/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/caffe2/python/scope.pyÚCurrentNameScope   s    
r   c                   C   s   t tdƒsd t_tjS )NÚdevicescope)r   r   r   r	   r	   r	   r
   ÚCurrentDeviceScope   s    
r   Fc              	   c   sŽ   t | tƒs| d u sJ dƒ‚tƒ }| r,| t nd} |r<| t_ntj|  t_z$d V  W tj | ¡sfJ dƒ‚|t_ntj | ¡s‚J dƒ‚|t_0 d S )Nz,NameScope takes in a string as its argument.r   zAThe namescope variable is changed from outside NameScope() calls.)Ú
isinstancer   r   Ú_NAMESCOPE_SEPARATORr   r   Úendswith)ÚprefixÚresetÚ	old_scoper	   r	   r
   Ú	NameScope#   s$    ÿÿþÿr   c                 c   sÖ   t  ¡ }| r,t| t jƒs J dƒ‚| | ¡ n|s8J dƒ‚|rB||_tƒ }|rh| d¡rh| d¡sh|j|_|r„t|dƒr„|j 	|j¡ |j 
¡  |t_z"d V  W tj|ks°J dƒ‚|t_ntj|ksÊJ dƒ‚|t_0 d S )Nz?DeviceScope takes in a caffe2_pb2.DeviceOption as its argument.z7At least one argument should be non-null in DeviceScopeÚ	node_nameÚ
extra_infoz=The device scope is changed from outside DeviceScope() calls.)r   ZDeviceOptionr   ZCopyFromr   r   ZHasFieldr   r   ÚextendÚsortr   r   )Úscoper   Z	new_scoper   r	   r	   r
   ÚDeviceScope7   s8    ÿÿ
ÿþÿr   c                  c   s8   t ƒ } zdt_dV  W | t_dS | t_   Y dS 0 dS )z©
    Allow users to 'disable' the name scope behaviour.

    This sets the CurrentNameScope() to None, so that the field is
    not set in CreateOperator(...), etc.
    r   N)r   r   r   ©r   r	   r	   r
   ÚEmptyNameScopeY   s    ÿr   c                  c   s8   t ƒ } zdt_dV  W | t_dS | t_   Y dS 0 dS )a"  
    Allow users to 'disable' the device scope behaviour (so it can be
    controlled at a NetDef::DeviceOption level, not overridden at
    OperatorDef::DeviceOption level).

    This sets the CurrentDeviceScope() to None, so that the field is
    not set in CreateOperator(...), etc.
    N)r   r   r   r   r	   r	   r
   ÚEmptyDeviceScopej   s    
ÿr   )F)N)Ú
contextlibÚ	threadingZpast.builtinsr   Zcaffe2.protor   r   Úlocalr   r   r   Úcontextmanagerr   r   r   r   r	   r	   r	   r
   Ú<module>   s   !
