o
    2h&                     @   s   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d
g dZdddZdd Zdd Z		dddZejdddZdS )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_initializedTc                 C   s8   t | ||}|rttjj| dS ttjj| dS )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resource r   Z/var/www/html/chatgem/venv/lib/python3.10/site-packages/tensorflow/python/ops/resources.pyregister_resource#   s   r   c                   C      t t jjS )z6Returns resources visible to all tasks in the cluster.)r   get_collectionr   r   r   r   r   r   shared_resources9      r   c                   C   r   )z7Returns resources intended to be local to this session.)r   r   r   r   r   r   r   r   local_resources>   r   r   report_uninitialized_resourcesc              	   C   s   | du r
t  t  } t|a tjdd}t|D | s5tj	g t
jdW  d   W  d   S ttdd | D }t	dd | D }t||W  d   W  d   S 1 scw   Y  W d   dS 1 ssw   Y  dS )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)dtypec                 S      g | ]}|j qS r   )r   .0rr   r   r   
<listcomp>`       z2report_uninitialized_resources.<locals>.<listcomp>c                 S   s   g | ]}|j jqS r   )r
   name)r"   sr   r   r   r$   c   s    )r   r   r   
name_scopeosenvirongetdevicer   constantr   stringr   logical_notr   stackboolean_mask)resource_listr&   local_devicevariables_maskvariable_names_tensorr   r   r   r   C   s,   

"initc                 C   s*   | rt jdd | D d|iS t j|dS )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.
  c                 S   r    r   )r   r!   r   r   r   r$   t   r%   z(initialize_resources.<locals>.<listcomp>r&   )r&   )r   groupno_op)r2   r&   r   r   r   initialize_resourcesh   s   r9   )T)Nr   )r6   )__doc__collectionsr)   tensorflow.python.frameworkr   r   tensorflow.python.opsr   r   r   r   tensorflow.python.utilr   
namedtupler	   r   r   r   r   should_use_resultr9   r   r   r   r   <module>   s*   

%