
    BVh                         d Z ddlmZ ddlZddlmZmZmZ ddlm	Z	 ddl
mZ  ed      Z G d d	ej                  ee         Z e       Zd
 Z edg      d        Zy)z+Classes used to handle thread-local stacks.    )IteratorN)GenericOptionalTypeVar)tf_contextlib)	tf_exportTc                        e Zd ZdZ fdZdee   fdZddZde	fdZ
ede	fd       Zej                  de	fd	       Zej                  d
edee   fd       Z xZS )DefaultStackz@A thread-local stack of objects for providing implicit defaults.c                 >    t         |           d| _        g | _        y )NT)super__init___enforce_nestingstack)self	__class__s    Q/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/framework/stack.pyr   zDefaultStack.__init__   s    	G DDJ    returnc                 <    | j                   r| j                   d   S d S )Nr   r   s    r   get_defaultzDefaultStack.get_default#   s    !ZZ4::b>1T1r   c                     g | _         y Nr   r   s    r   resetzDefaultStack.reset&   s	    DJr   c                     | j                    S r   r   r   s    r   
is_clearedzDefaultStack.is_cleared)   s    zz>r   c                     | j                   S r   r   r   s    r   enforce_nestingzDefaultStack.enforce_nesting,   s       r   valuec                     || _         y r   r!   )r   r#   s     r   r"   zDefaultStack.enforce_nesting0   s
    !Dr   defaultc              #   2  K   | j                   j                  |       	 | | j                   rk| j                  rC| j                   d   |urt        dt	        |      z        | j                   j                          y| j                   j                  |       yy# | j                   rk| j                  rC| j                   d   |urt        dt	        |      z        | j                   j                          w | j                   j                  |       w w xY ww)z3A context manager for manipulating a default stack.r   z0Nesting violated for default stack of %s objectsN)r   appendr   AssertionErrortypepopremove)r   r%   s     r   get_controllerzDefaultStack.get_controller4   s      	JJg%m 
  ZZ^7* BW  **..

**

G
$ 
  ZZ^7* BW  **..

**

G
$ 
s   DB A8DA9DD)r   N)__name__
__module____qualname____doc__r   r   r	   r   r   boolr   propertyr"   setterr   contextmanagerr   r,   __classcell__)r   s   @r   r   r      s    H
28A; 2$  !t ! ! "4 " " %A %(1+ %  %r   r   c                 ,    t         j                  |       S )a  Python "with" handler for defining a default session.

  This function provides a means of registering a session for handling
  Tensor.eval() and Operation.run() calls. It is primarily intended for use
  by session.Session, but can be used with any object that implements
  the Session.run() interface.

  Use with the "with" keyword to specify that Tensor.eval() and Operation.run()
  invocations within the scope of a block should be executed by a particular
  session.

  The default session applies to the current thread only, so it is always
  possible to inspect the call stack and determine the scope of a default
  session. If you create a new thread, and wish to use the default session
  in that thread, you must explicitly add a "with ops.default_session(sess):"
  block in that thread's function.

  Example:
    The following code examples are equivalent:

    # 1. Using the Session object directly:
    sess = ...
    c = tf.constant(5.0)
    sess.run(c)

    # 2. Using default_session():
    sess = ...
    with ops.default_session(sess):
      c = tf.constant(5.0)
      result = c.eval()

    # 3. Overriding default_session():
    sess = ...
    with ops.default_session(sess):
      c = tf.constant(5.0)
      with ops.default_session(...):
        c.eval(session=sess)

  Args:
    session: The session to be installed as the default session.

  Returns:
    A context manager for the default session.
  )_default_session_stackr,   )sessions    r   default_sessionr9   J   s    Z 
 	.	.w	77r   get_default_session)v1c                  *    t         j                         S )a  Returns the default session for the current thread.

  The returned `Session` will be the innermost session on which a
  `Session` or `Session.as_default()` context has been entered.

  NOTE: The default session is a property of the current thread. If you
  create a new thread, and wish to use the default session in that
  thread, you must explicitly add a `with sess.as_default():` in that
  thread's function.

  Returns:
    The default `Session` being used in the current thread.
  )r7   r    r   r   r:   r:   z   s     
 	+	+	--r   )r0   collections.abcr   	threadingtypingr   r   r   tensorflow.python.utilr    tensorflow.python.util.tf_exportr   r	   localr   r7   r9   r:   r=   r   r   <module>rD      si    2 $  - - 0 6CL)%9??GAJ )%X & -8` $%&. '.r   