o
    ?eg                     @   sX   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d Zd	Z	d
d Z
dS )zTensor shape utilities.    )context)dtypes)ops)tensor_shape)tensor_utilc                 C   s>   d}t | ttfr| stj}ntttj| } tj	| |ddS )zBConvert to an int32 or int64 tensor, defaulting to int32 if empty.Nshape)dtypename)

isinstancetuplelistr   Zint32mapr   Zdimension_valuer   Zconvert_to_tensor)r   r    r   a/home/www/facesmatcher.com/pyenv/lib/python3.10/site-packages/tensorflow/python/ops/shape_util.pyshape_tensor   s   r   Tc                 C   s^   t r%t s't jr)| j s+t	|r-t
|}t|}| | dS dS dS dS dS dS )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   Zexecuting_eagerlyr   Zget_default_graphZbuilding_functionr   Zis_fully_definedr   Z	is_tensorr   Zconstant_value_as_shape	set_shape)Ztensorr   Zconst_shaper   r   r   maybe_set_static_shape*   s   
r   N)__doc__Ztensorflow.python.eagerr   Ztensorflow.python.frameworkr   r   r   r   r   r   r   r   r   r   r   <module>   s   