3
Eg' ã @ s„ d dl Z d dlZd dlmZ d dlmZ dZejƒ add„ Z dd„ Z
e jdd
d„ƒZe jddd
„ƒZ
e jdd„ ƒZe jdd„ ƒZdS )é N)Ú
basestring)Ú
caffe2_pb2ú/c C s t tdƒsdt_tjS )NÚ namescopeÚ )ÚhasattrÚ_threadlocal_scoper © r r ú?/usr/local/lib64/python3.6/site-packages/caffe2/python/scope.pyÚCurrentNameScope s
r c C s t tdƒsd t_tjS )NÚdevicescope)r r r r r r r
ÚCurrentDeviceScope s
r
Fc c st t | tƒs| d kstdƒ‚tƒ }| r,| t nd} |r<| t_ntj| t_z
d V W d tjj| ƒshtdƒ‚|t_X d S )Nz,NameScope takes in a string as its argument.r zAThe namescope variable is changed from outside NameScope() calls.)Ú
isinstancer ÚAssertionErrorr Ú_NAMESCOPE_SEPARATORr r Úendswith)ÚprefixÚresetÚ old_scoper r r
Ú NameScope# s
r c c sÀ t jƒ }| r,t| t jƒs tdƒ‚|j| ƒ n|s8tdƒ‚|rB||_tƒ }|rj|jdƒrj|jdƒ rj|j|_|r†t|dƒr†|j j
|j ƒ |j jƒ |t_
z
d V W d tj
|ks´tdƒ‚|t_
X 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 ZDeviceOptionr r ZCopyFromr r
ZHasFieldr r ÚextendÚsortr r )Zscoper Z new_scoper r r r
ÚDeviceScope7 s*
r c c s" t ƒ } zdt_dV W d| t_dS )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 s" t ƒ } zdt_dV W d| t_dS )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 Zcaffe2.protor r Úlocalr r r
Úcontextmanagerr r r r r r r r
Ú