a
    /Sic                     @   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 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)control_flow_ops)math_ops)tf_should_use	_Resource)handlecreateis_initializedTc                 C   s6   t | ||}|r"ttjj| n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   [/var/www/html/django/DPS/env/lib/python3.9/site-packages/tensorflow/python/ops/resources.pyregister_resource"   s    r   c                   C   s   t t jjS )z6Returns resources visible to all tasks in the cluster.)r   get_collectionr   r   r   r   r   r   shared_resources8   s    r   c                   C   s   t t jjS )z7Returns resources intended to be local to this session.)r   r   r   r   r   r   r   r   local_resources=   s    r   report_uninitialized_resourcesc              	   C   s   | du rt  t  } t| tjdd}t| | sjt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 s0    Y  W d   n1 s0    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   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    b   r!   )r   r   r   
name_scopeosenvirongetdevicer   constantr   stringr   logical_notstackboolean_mask)resource_listr"   local_devicevariables_maskvariable_names_tensorr   r   r   r   B   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   s   g | ]
}|j qS r   )r
   r   r   r   r   r    s   r!   z(initialize_resources.<locals>.<listcomp>r"   )r"   )r   groupno_op)r.   r"   r   r   r   initialize_resourcesg   s    r5   )T)Nr   )r2   )__doc__collectionsr%   tensorflow.python.frameworkr   r   tensorflow.python.opsr   r   r   tensorflow.python.utilr   
namedtupler   r   r   r   r   should_use_resultr5   r   r   r   r   <module>   s&   
  
%