
    AVh                        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
j0                  Ze
j2                  Ze
j4                  Ze
j6                  Zd ZddZd Zd Zy)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)nestbiaskernelc                 >    fd}t        j                  ||       S )zCCreate tensors of zeros based on state_size, batch_size, and dtype.c                     t        |       }t        j                  |      }t        j                         st        | d      }|j                  |       |S )z7Combine s with batch_size to get a proper tensor shape.dtypeT)static)_concatr
   zerosr   executing_eagerly	set_shape)scsizec_static
batch_sizer   s       S/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/ops/rnn_cell_impl.pyget_state_shapez,_zero_state_tensors.<locals>.get_state_shape5   sJ    
AA??1E*D$$&Qt4h
nnXK    )r   map_structure)
state_sizer   r   r   s    `` r   _zero_state_tensorsr!   2   s     
		OZ	88r   c                    t        | t        j                        rn| }t        j                  |       }|j
                  j                  dk(  rt        j                  |d      }n|j
                  j                  dk7  rt        d|z        t        j                  |       }|j                  |j                         nd}|j                         r3t        j                  |j                         t         j"                        nd}t        |t        j                        rn|}t        j                  |      }|j
                  j                  dk(  rt        j                  |d      }n|j
                  j                  dk7  rt        d|z        t        j                  |      }|j                  |j                         nd}|j                         r3t        j                  |j                         t         j"                        nd}|rFt        j                  |      j%                  |      }|j                  |j                         }|S d}|S ||t        d| d|      t        j&                  ||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: z and )
isinstancer   Tensorr   constant_valueshapendimsr
   expand_dims
ValueErrorr   TensorShapeas_listis_fully_definedr   constantr   int32concatenateconcat)prefixsuffixr   pp_staticr   s_staticr'   s           r   r   r   A   s   , &A))&1Hww}}


1
%a	
!	
O 
 	  (Agg1qyy{tH  	QYY[= 
 &A))&1Hww}}


1
%a	
!	
O 
 	  (Agg1qyy{tH  	QYY[=  $$X.::8DE${{6EMMOE 
, =AE 
, 	yAI>Df
M  aVQ'E	,r   c                 <    	 t        | |       y# t        $ r Y yw xY w)NTF)getattrAttributeError)obj	attr_names     r   _hasattrr<      s*    C  
 s    	c           	      <   t        |d      t        |d      t        |d      xs t        |d      t        |      g}g d}t        |      sLt        ||      D cg c]
  \  }}|r	| }}}t	        dj                  | |dj                  |                  yc c}}w )	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.
  output_sizer    get_initial_state
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 callablez-The argument {!r} ({}) is not an RNNCell: {}.z, N)r<   callableallzip	TypeErrorformatjoin)	cell_namecell
conditionserrorserrorconds         r   assert_like_rnncellrM      s      t]#t\"t()IXdL-Itn	*& 
Z'*6:'>KtdeKFK
7>>tTYYv.	
  
Ks   
B%BN)F) __doc__tensorflow.python.eagerr   tensorflow.python.frameworkr   r   r   r   r   )tensorflow.python.keras.layers.legacy_rnnr	   tensorflow.python.opsr
   tensorflow.python.utilr   _BIAS_VARIABLE_NAME_WEIGHTS_VARIABLE_NAMEBasicLSTMCellBasicRNNCellDeviceWrapperDropoutWrapperGRUCellLayerRNNCellLSTMCellLSTMStateTupleMultiRNNCellResidualWrapperRNNCellr!   r   r<   rM    r   r   <module>rb      s    , 3 . . 4 3 C + '  ! ++))++--


))!!--))//


9DN"r   