
    BVh^                     D    d Z ddlmZ ddlmZ ddlmZ ddlmZ d Zd Zy)	z)Utility to manipulate resource variables.    )composite_tensor)ops)_pywrap_utils)nestc                 4    d }t        j                  ||       S )a  Converts `ResourceVariable`s in `values` to `Tensor`s.

  If an object is a `CompositeTensor` and overrides its
  `_convert_variables_to_tensors` method, its `ResourceVariable` components
  will also be converted to `Tensor`s. Objects other than `ResourceVariable`s
  in `values` will be returned unchanged.

  Args:
    values: A nested structure of `ResourceVariable`s, or any other objects.

  Returns:
    A new structure with `ResourceVariable`s in `values` converted to `Tensor`s.
  c                     t        j                  |       rt        j                  |       S t	        | t
        j                        rt        j                  |       S | S )N)r   IsResourceVariabler   convert_to_tensor
isinstancer   CompositeTensorconvert_variables_to_tensorsxs    U/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/util/variable_utils.py$_convert_resource_variable_to_tensorzJconvert_variables_to_tensors.<locals>._convert_resource_variable_to_tensor%   sH    ''*""1%%	A'77	8::1==h    r   map_structure)valuesr   s     r   r   r      s     
		@&	IIr   c                 4    d }t        j                  ||       S )a  Replaces `ResourceVariable`s in `values` with tf.nest atoms.

  This function is mostly for backward compatibility. Historically,
  `ResourceVariable`s are treated as tf.nest atoms. This is no
  longer the case after `ResourceVariable` becoming `CompositeTensor`.
  Unfortunately, tf.nest doesn't allow customization of what objects
  are treated as atoms. Calling this function to manually convert
  `ResourceVariable`s to atoms to avoid breaking tf.assert_same_structure
  with inputs of a `ResourceVariable` and an atom, like a `Tensor`.

  The specific implementation uses 0 as the tf.nest atom, but other tf.nest
  atoms could also serve the purpose. Note, the `TypeSpec` of None is not a
  tf.nest atom.

  Objects other than `ResourceVariable`s in `values` will be returned unchanged.

  Note: this function does not look into `CompositeTensor`s. Replacing
  `ResourceVariable`s in a `CompositeTensor` with atoms will change the
  `TypeSpec` of the `CompositeTensor`, which violates the semantics of
  `CompositeTensor` and tf.nest. So `ResourceVariable`s in `CompositeTensor`s
  will be returned as they are.

  Args:
    values: A nested structure of `ResourceVariable`s, or any other objects.

  Returns:
    A new structure with `ResourceVariable`s in `values` converted to atoms.
  c                 2    t        j                  |       ry| S )Nr   )r   r	   r   s    r   $_replace_resource_variable_with_atomzJreplace_variables_with_atoms.<locals>._replace_resource_variable_with_atomM   s    ''*hr   r   )r   r   s     r   replace_variables_with_atomsr   0   s    : 
		@&	IIr   N)	__doc__tensorflow.python.frameworkr   r   tensorflow.python.utilr   r   r   r    r   r   <module>r      s"    0 8 + 0 'J2#Jr   