
    AVhg                     T    d 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 ZdZ	d	 Z
y
)zTensor shape utilities.    )context)dtypes)ops)tensor_shape)tensor_utilc                     d}t        | t        t        f      r6| st        j                  }n#t        t        t        j                  |             } t        j                  | |d      S )zBConvert to an int32 or int64 tensor, defaulting to int32 if empty.Nshape)dtypename)

isinstancetuplelistr   int32mapr   dimension_valuer   convert_to_tensor)r	   r
   s     P/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/ops/shape_util.pyshape_tensorr      sO    
%t}%lle C44e<=e			uE	@@    Tc                 >   t         rt        j                         st        j                         j
                  rc| j                  j                         sHt        j                  |      r2t        |      }t        j                  |      }| j                  |       yyyyyy)a&  Sets the shape of `tensor` to the `shape`'s constant value, if inferrable.

  This is a temporary workaround to fix shape inference across functional op
  boundaries. E.g.

  ```python
  shape = tf.constant([3])
  @tf.function
  def f():
    u = tf.random_uniform(shape)
    return u
  ```

  If we were to rely solely on C++ shape inference, the shape of `u` inside
  `f` would be unknown because C++ shape inference is not aware of the outer
  graph and all it sees is a Placeholder node when backtracing the captured
  tensor for `shape`. `maybe_set_static_shape` computes the static shape value
  of `shape` by traversing the `FuncGraph` boundaries and sets the correct
  shape.

  A longer term solution would be to fix C++ shape inference.

  Args:
    tensor: A tensor.
    shape: A shape tensor.
  N)_ENABLE_MAYBE_SET_STATIC_SHAPEr   executing_eagerlyr   get_default_graphbuilding_functionr	   is_fully_definedr   	is_tensorr   constant_value_as_shape	set_shape)tensorr	   const_shapes      r   maybe_set_static_shaper!   *   s    6 %W-F-F-H	//
,,
'
'
)k.C.CE.JE55e<K
[! /K
) 0 .I$r   N)__doc__tensorflow.python.eagerr   tensorflow.python.frameworkr   r   r   r   r   r   r!    r   r   <module>r&      s,     + . + 4 3A  "&  "r   