
    AVh&                         d Z ddlZddlZddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 dd	lmZ  ej                  d
g d      ZddZd Zd Z	 	 ddZej&                  dd       Zy)z&Utilities for using generic resources.    N)dtypes)ops)	array_ops)array_ops_stack)control_flow_ops)math_ops)tf_should_use	_Resource)handlecreateis_initializedc                     t        | ||      }|r/t        j                  t        j                  j                  |       yt        j                  t        j                  j
                  |       y)a  Registers a resource into the appropriate collections.

  This makes the resource findable in either the shared or local resources
  collection.

  Args:
   handle: op which returns a handle for the resource.
   create_op: op which initializes the resource.
   is_initialized_op: op which returns a scalar boolean tensor of whether
    the resource has been initialized.
   is_shared: if True, the resource gets added to the shared resource
    collection; otherwise it gets added to the local resource collection.

  N)r
   r   add_to_collection	GraphKeys	RESOURCESLOCAL_RESOURCES)r   	create_opis_initialized_op	is_sharedresources        O/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/ops/resources.pyregister_resourcer   #   sJ     vy*;<(#--118<#--77B    c                  \    t        j                  t         j                  j                        S )z6Returns resources visible to all tasks in the cluster.)r   get_collectionr   r    r   r   shared_resourcesr   9   s    			CMM33	44r   c                  \    t        j                  t         j                  j                        S )z7Returns resources intended to be local to this session.)r   r   r   r   r   r   r   local_resourcesr   >   s    			CMM99	::r   c           
         | t               t               z   } t        j                  |      5  t        j
                  j                  dd      }t        j                  |      5  | s7t        j                  g t        j                        cddd       cddd       S t        j                  t        j                  | D cg c]  }|j                    c}            }t        j                  | D cg c]  }|j"                  j$                   c}      }t        j&                  ||      cddd       cddd       S c c}w c c}w # 1 sw Y   nxY w	 ddd       y# 1 sw Y   yxY w)a  Returns the names of all uninitialized resources in resource_list.

  If the returned tensor is empty then all resources have been initialized.

  Args:
   resource_list: resources to check. If None, will use shared_resources() +
    local_resources().
   name: name for the resource-checking op.

  Returns:
   Tensor containing names of the handles of all resources which have not
   yet been initialized.

  N.TF_DEVICE_FOR_UNINITIALIZED_VARIABLE_REPORTINGz/cpu:0)dtype)r   r   r   
name_scopeosenvirongetdevicer   constantr   stringr   logical_notr   stackr   r   nameboolean_mask)resource_listr,   local_devicervariables_masksvariable_names_tensors          r   report_uninitialized_resourcesr4   C   s>     $&)::M
~~d K::>>8(DL	L	! K !!"FMM:	K K	K K  ++


= Ia!1!1 I
JLn (00"/
0Q188==
02 ##$9>JK K	K K !J 1K K K	K K KsM   6E#'E
	E"E?D<E0EE)	E<
EE	EE%c                     | r-t        j                  | D cg c]  }|j                   c}d|iS t        j                  |      S c c}w )zInitializes the resources in the given list.

  Args:
   resource_list: list of resources to initialize.
   name: name of the initialization op.

  Returns:
   op responsible for initializing all resources.
  r,   )r,   )r   groupr   no_op)r.   r,   r0   s      r   initialize_resourcesr8   h   sC     !!m#DAHH#DP4PP			T	** $Es   A)T)Nr4   )init)__doc__collectionsr$   tensorflow.python.frameworkr   r   tensorflow.python.opsr   r   r   r   tensorflow.python.utilr	   
namedtupler
   r   r   r   r4   should_use_resultr8   r   r   r   <module>rA      sx   " -  	 . + + 1 2 * 0 #K"";#IK	C,5
;
 26(H"KJ   + !+r   