
    BVh!                         d Z ddlZddlmZ ddlmZ ddlmZ  edg        G d d	ej                  
             Z	d Z
d Zy)z6Tensor-like objects that are composed from tf.Tensors.    N)pywrap_tensorflow)nest)	tf_exportz__internal__.CompositeTensor)v1c                   L    e Zd ZdZej
                  d        Zd Zd Zd Z	d Z
y)CompositeTensora
  Abstract base class for Tensor-like objects that are composed from Tensors.

  Each `CompositeTensor` can be decomposed into a structured collection of
  component `tf.Tensor`s, and reconstructed from those components.

  The `tensorflow.python.util.nest` module has support for treating composite
  tensors as structure, which makes it easy to flatten and reconstruct
  composite tensors (or larger structures that contain composite tensors).
  E.g.:

  ```python
  ct = ...  # Create a composite tensor.
  flat_list_of_tensors = nest.flatten(ct, expand_composites=True)
  transformed_list_of_tensors = ...  # do something with the flat tensors.
  result = nest.pack_sequence_as(ct, transformed_list_of_tensors,
                                 expand_composites=True)
  ```
  c                 D    t        t        |       j                   d      )z/A `TypeSpec` describing the type of this value.z._type_spec()NotImplementedErrortype__name__selfs    \/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/framework/composite_tensor.py
_type_speczCompositeTensor._type_spec-   s!     d!4!4 5]C
DD    c                 D    t        t        |       j                   d      )a  Returns a TypeSpec given a shape invariant (used by `tf.while_loop`).

    Args:
      shape: A `tf.TensorShape` object.  The shape invariant for this
        `CompositeTensor`, or `None` if a default shape invariant should be used
        (based on the value of this `CompositeTensor`).

    Returns:
      A nested structure whose values are `tf.TensorShape` objects, specifying
      the shape invariants for the tensors that comprise this `CompositeTensor`.
    z._shape_invariant_to_type_specr
   )r   shapes     r   _shape_invariant_to_type_specz-CompositeTensor._shape_invariant_to_type_spec2   s)     :
=>@ @r   c           
          t        j                  t        j                  | d      D cg c]  }t        |dd      |j                         ! c}      }t	        t        |            S c c}w )zReturns a list of `Operation`s that consume this `CompositeTensor`.

    Returns:
      A list of `Operation`s.

    Raises:
      RuntimeError: If this method is called while executing eagerly.
    Texpand_compositesgraphN)r   flattengetattr	consumerslistset)r   	componentr   s      r   
_consumerszCompositeTensor._consumersD   sa     ddC9gt,8 	 I
 Is   $A(c                 8    | j                   j                  |      S N)r   __tf_tracing_type__)r   contexts     r   r#   z#CompositeTensor.__tf_tracing_type__T   s    ??..w77r   c                     | S )aL  Converts ResourceVariable components to Tensors.

    Override this method to explicitly convert ResourceVariables embedded in the
    CompositeTensor to Tensors. By default, it returns the CompositeTensor
    unchanged.

    Returns:
      A CompositeTensor with all its ResourceVariable components converted to
      Tensors.
     r   s    r   _convert_variables_to_tensorsz-CompositeTensor._convert_variables_to_tensorsW   s	     Kr   N)r   
__module____qualname____doc__abcabstractpropertyr   r   r    r#   r'   r&   r   r   r   r      s8    & E E@$  8r   r   )	metaclassc                     t        | t              r$t        | j                  j	                  |             S t        j                  |       s| S t        j                  t        | d      S )a  Recursively replaces CompositeTensors with their components.

  Args:
    structure: A `nest`-compatible structure, possibly containing composite
      tensors.

  Returns:
    A copy of `structure`, where each composite tensor has been replaced by
    its components.  The result will contain no composite tensors.
    Note that `nest.flatten(replace_composites_with_components(structure))`
    returns the same value as `nest.flatten(structure)`.
  Fr   )
isinstancer   "replace_composites_with_componentsr   _to_componentsr   	is_nestedmap_structure)	structures    r   r0   r0   e   s]     	?+-++I68 8>>)$*IP Pr   c                 "    | j                         S r"   )r'   )composite_tensors    r   convert_variables_to_tensorsr7   |   s    		7	7	99r   )r*   r+   tensorflow.pythonr   tensorflow.python.utilr    tensorflow.python.util.tf_exportr   ABCMetar   r0   r7   r&   r   r   <module>r<      sL    = 
 / ' 6 )b1I I 2IXP.:r   