o
    ?e                     @   s   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lmZ ddl	m
Z
 dd	lmZ dd
lmZ dZdZe
jZe
jZe
jZe
jZe
jZe
jZe
jZe
jZe
jZe
jZe
jZdd ZdddZdd Zdd ZdS )av  Module implementing RNN Cells.

This module provides a number of basic commonly used RNN cells, such as LSTM
(Long Short Term Memory) or GRU (Gated Recurrent Unit), and a number of
operators that allow adding dropouts, projections, or embeddings for inputs.
Constructing multi-layer cells is supported by the class `MultiRNNCell`, or by
calling the `rnn` ops several times.
    )context)constant_op)dtypes)tensor)tensor_shape)tensor_util)rnn_cell_impl)	array_ops)nestZbiasZkernelc                    s    fdd}t || S )zCCreate tensors of zeros based on state_size, batch_size, and dtype.c                    s<   t  | }tj|d}t st  | dd}|| |S )z7Combine s with batch_size to get a proper tensor shape.dtypeT)static)_concatr	   Zzerosr   Zexecuting_eagerly	set_shape)scsizeZc_static
batch_sizer    d/home/www/facesmatcher.com/pyenv/lib/python3.10/site-packages/tensorflow/python/ops/rnn_cell_impl.pyget_state_shape5   s   

z,_zero_state_tensors.<locals>.get_state_shape)r
   Zmap_structure)
state_sizer   r   r   r   r   r   _zero_state_tensors2   s   	r   Fc                 C   s  t | tjr'| }t| }|jjdkrt|d}qG|jjdkr&t	d| n t
| }|jdur5| nd}| rEtj| tjdnd}t |tjrn|}t|}|jjdkrat|d}q|jjdkrmt	d| n t
|}|jdur|| nd}| rtj| tjdnd}|rt
||}|jdur| }|S d}|S |du s|du rt	d| |f t||fd}|S )a  Concat that enables int, Tensor, or TensorShape values.

  This function takes a size specification, which can be an integer, a
  TensorShape, or a Tensor, and converts it into a concatenated Tensor
  (if static = False) or a list of integers (if static = True).

  Args:
    prefix: The prefix; usually the batch size (and/or time step size).
      (TensorShape, int, or Tensor.)
    suffix: TensorShape, int, or Tensor.
    static: If `True`, return a python list with possibly unknown dimensions.
      Otherwise return a `Tensor`.

  Returns:
    shape: the concatenation of prefix and suffix.

  Raises:
    ValueError: if `suffix` is not a scalar or vector (or TensorShape).
    ValueError: if prefix or suffix was `None` and asked for dynamic
      Tensors out.
  r      zCprefix tensor must be either a scalar or vector, but saw tensor: %sNr   zCsuffix tensor must be either a scalar or vector, but saw tensor: %sz.Provided a prefix or suffix of None: %s and %s)
isinstancer   ZTensorr   Zconstant_valueshapeZndimsr	   Zexpand_dims
ValueErrorr   ZTensorShapeas_listZis_fully_definedr   Zconstantr   Zint32Zconcatenateconcat)prefixsuffixr   pZp_staticr   Zs_staticr   r   r   r   r   A   s`   




r   c                 C   s&   zt | | W dS  ty   Y dS w )NFT)getattrAttributeError)objZ	attr_namer   r   r   _hasattr   s   r&   c                 C   sl   t |dt |dt |dpt |dt|g}g d}t|s4dd t||D }td| |d	|d
S )a  Raises a TypeError if cell is not like an RNNCell.

  NOTE: Do not rely on the error message (in particular in tests) which can be
  subject to change to increase readability. Use
  ASSERT_LIKE_RNNCELL_ERROR_REGEXP.

  Args:
    cell_name: A string to give a meaningful error referencing to the name of
      the functionargument.
    cell: The object which should behave like an RNNCell.

  Raises:
    TypeError: A human-friendly exception.
  Zoutput_sizer   Zget_initial_stateZ
zero_state)z!'output_size' property is missingz 'state_size' property is missingz=either 'zero_state' or 'get_initial_state' method is requiredzis not callablec                 S   s   g | ]\}}|s|qS r   r   ).0errorZcondr   r   r   
<listcomp>   s    z'assert_like_rnncell.<locals>.<listcomp>z-The argument {!r} ({}) is not an RNNCell: {}.z, N)r&   callableallzip	TypeErrorformatjoin)Z	cell_namecellZ
conditionserrorsr   r   r   assert_like_rnncell   s   r2   N)F) __doc__Ztensorflow.python.eagerr   Ztensorflow.python.frameworkr   r   r   r   r   Z)tensorflow.python.keras.layers.legacy_rnnr   Ztensorflow.python.opsr	   Ztensorflow.python.utilr
   Z_BIAS_VARIABLE_NAMEZ_WEIGHTS_VARIABLE_NAMEZBasicLSTMCellZBasicRNNCellZDeviceWrapperZDropoutWrapperZGRUCellZLayerRNNCellZLSTMCellZLSTMStateTupleZMultiRNNCellZResidualWrapperZRNNCellr   r   r&   r2   r   r   r   r   <module>   s6   
G	