a
    ==ic                     @   s8   d dl Z d dlmZ G dd deZG dd deZdS )    N)	workspacec                   @   s$   e Zd Zdd Zdd Zdd ZdS )_WorkspaceCtxc                 C   s   || _ g | _d S N)workspace_idworkspace_stack)selfr    r   m/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/caffe2/python/onnx/workspace.py__init__   s    z_WorkspaceCtx.__init__c                 C   s$   | j t  tj| jdd d S NT)Zcreate_if_missing)r   appendr   ZCurrentWorkspaceSwitchWorkspacer   r   r   r   r	   	__enter__   s    z_WorkspaceCtx.__enter__c                 C   s   | j  }tj|dd d S r   )r   popr   r   )r   exc_type	exc_value	tracebackwr   r   r	   __exit__   s    
z_WorkspaceCtx.__exit__N)__name__
__module____qualname__r
   r   r   r   r   r   r	   r      s   r   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )		WorkspaceaA  
    An object representing a Caffe2 workspace.  It is a context manager,
    so you can say 'with workspace:' to use the represented workspace
    as your global workspace.  It also supports every method supported
    by caffe2.python.workspace, but instead of running these operations
    in the global workspace, it runs them in the workspace represented
    by this object.  When this object goes dead, the workspace (and all
    nets and blobs within it) are freed.

    Why do we need this class?  Caffe2's workspace model is very "global state"
    oriented, in that there is always some ambient global workspace you are
    working in which holds on to all of your networks and blobs.  This class
    makes it possible to work with workspaces more locally, and without
    forgetting to deallocate everything in the end.
    c                 C   s   t tt | _d S r   )r   struuiduuid4_ctxr   r   r   r	   r
   5   s    zWorkspace.__init__c                    s    fdd}|S )Nc                     s>   j $ tt | i |W  d    S 1 s00    Y  d S r   )r   getattrr   )argskwargsattrr   r   r	   f=   s    z Workspace.__getattr__.<locals>.fr   )r   r"   r#   r   r!   r	   __getattr__<   s    zWorkspace.__getattr__c                 C   s   |    d S r   )ZResetWorkspacer   r   r   r	   __del__B   s    zWorkspace.__del__N)r   r   r   __doc__r
   r$   r%   r   r   r   r	   r   %   s   r   )r   Zcaffe2.pythonr   objectr   r   r   r   r   r	   <module>	   s   