
    BVh                     N    d Z ddlmZ ddlmZ ddlmZ d Zd Z	 	 	 d
dZdd	Z	y)zSpecial functions that only make sense for AutoGraph.

These functions are meant to ensure feature parity between Python and AutoGraph,
so that the exact same code works in both modes. In general, AutoGraph will
replace these calls.
    )data_structures)constant_op)tensor_utilc                     ||yt        j                  |       ryt        | t        t        f      r| ryt        d      t        dj                  t        |                   )z$Validates the inputs of tensor_list.NzDelement_dtype and element_shape are required when elements are emptyzFunknown type for elements: {}; only Tensor, list and tuple are allowed)r   
is_tf_type
isinstancelisttuple
ValueErrorformattype)elementselement_dtypeelement_shapes      b/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/autograph/lang/special_functions.py_validate_list_constructorr      si    =#<
H%
4-(  	X'	) )    c                 Z    t        j                  |      rt        j                  |       S | S )z8Casts a value to be staged at the same level as another.)r   r   r   constant)value
like_values     r   match_staging_levelr   .   s&    J'&&	,r   Nc                 |    t        | ||       |rt        j                  | ||      S t        j                  | ||      S )a  Creates an tensor list and populates it with the given elements.

  This function provides a more uniform access to tensor lists and tensor
  arrays, and allows optional initialization.

  Note: this function is a simplified wrapper. If you need greater control,
  it is recommended to use the underlying implementation directly.

  Args:
    elements: Iterable[tf.Tensor, ...], the elements to initially fill the list
        with
    element_dtype: Optional[tf.DType], data type for the elements in the list;
        required if the list is empty
    element_shape: Optional[tf.TensorShape], shape for the elements in the list;
        required if the list is empty
    use_tensor_array: bool, whether to use the more compatible but restrictive
        tf.TensorArray implementation
  Returns:
    Union[tf.Tensor, tf.TensorArray], the new list.
  Raises:
    ValueError: for invalid arguments
  )r   r   tf_tensor_array_newtf_tensor_list_new)r   r   r   use_tensor_arrays       r   tensor_listr   5   sI    4 X}mD..x/<> > --h.;= =r   c                 n    |rd }|}nd }t        j                  | t        j                  ||            S )a"  Stacks the input, if it admits the notion of stacking.

  For example, a list of tensors can be stacked into a larger tensor. This
  function is similar to tf.stack, but it accepts non-lists and lists of
  non-tensors as arguments. In the latter case, the function does nothing.

  Args:
    list_or_tensor: Any
    element_dtype: tf.DType, optional dtypedtype for the elements in the list.
        Required if the input is stackable, and the list is untyped.
    strict: bool, if True an error is raised if the input is not stackable.
        Otherwise the function is a no-op.

  Returns:
    Any, if the input is stackable, the result will be a tf.Tensor. Otherwise,
    if strict=False, the result will be list_or_tensor.

  Raises:
    ValueError: if strict=True and the input is not stackable.
  c                     t        d| z        )Nz%%s must be stackable when strict=True)r   xs    r   raise_errorzstack.<locals>.raise_errorn   s    >BCCr   c                     | S )N r    s    r   <lambda>zstack.<locals>.<lambda>r   s    a r   )r   original_call)r   
list_stackListStackOpts)list_or_tensorr   strictr"   r&   s        r   stackr+   X   sC    * DMM		#	###%]D
E Er   )NNF)NT)
__doc__%tensorflow.python.autograph.operatorsr   tensorflow.python.frameworkr   r   r   r   r   r+   r$   r   r   <module>r/      s7    B 3 3)& #"!& =FEr   