o
    ?e&                     @   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   Zadd_to_collection	GraphKeys	RESOURCESLOCAL_RESOURCES)r
   Z	create_opZis_initialized_opZ	is_sharedresource r   `/home/www/facesmatcher.com/pyenv/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.

  NZ.TF_DEVICE_FOR_UNINITIALIZED_VARIABLE_REPORTINGz/cpu:0)Z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   Z
name_scopeosenvirongetZdevicer   Zconstantr   stringr   Zlogical_notr   stackZboolean_mask)resource_listr    Zlocal_deviceZvariables_maskZ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   groupZno_op)r'   r    r   r   r   initialize_resourcesh   s   r*   )T)Nr   )r(   )__doc__collectionsr"   Ztensorflow.python.frameworkr   r   Ztensorflow.python.opsr   r   r   r   Ztensorflow.python.utilr   
namedtupler	   r   r   r   r   Zshould_use_resultr*   r   r   r   r   <module>   s*   

%