
    6biM                     $   S r SSKJs  Jr  SSKJr  SSKJr  SSKJr  SSKJ	r	  SSKJ
r
  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  \" S5       " S S\\R8                  5      5       r\" S5       " S S\5      5       rg)zFully connected RNN layer.    N)activations)backend)constraints)initializers)regularizers)
base_layer)	InputSpec)	rnn_utils)RNN)DropoutRNNCellMixin)tf_utils)
tf_logging)keras_exportzkeras.layers.SimpleRNNCellc                      ^  \ rS rSrSr             S	U 4S jjr\R                  U 4S j5       rS
S jr	SS jr
U 4S jrSrU =r$ )SimpleRNNCell%   a
  Cell class for SimpleRNN.

See
[the TF-Keras RNN API guide](https://www.tensorflow.org/guide/tf_keras/rnn)
for details about the usage of RNN API.

This class processes one step within the whole time sequence input, whereas
`tf.keras.layer.SimpleRNN` processes the whole sequence.

Args:
  units: Positive integer, dimensionality of the output space.
  activation: Activation function to use.
    Default: hyperbolic tangent (`tanh`).
    If you pass `None`, no activation is applied
    (ie. "linear" activation: `a(x) = x`).
  use_bias: Boolean, (default `True`), whether the layer uses a bias vector.
  kernel_initializer: Initializer for the `kernel` weights matrix,
    used for the linear transformation of the inputs. Default:
    `glorot_uniform`.
  recurrent_initializer: Initializer for the `recurrent_kernel`
    weights matrix, used for the linear transformation of the recurrent
    state.  Default: `orthogonal`.
  bias_initializer: Initializer for the bias vector. Default: `zeros`.
  kernel_regularizer: Regularizer function applied to the `kernel` weights
    matrix. Default: `None`.
  recurrent_regularizer: Regularizer function applied to the
    `recurrent_kernel` weights matrix. Default: `None`.
  bias_regularizer: Regularizer function applied to the bias vector.
    Default: `None`.
  kernel_constraint: Constraint function applied to the `kernel` weights
    matrix. Default: `None`.
  recurrent_constraint: Constraint function applied to the
    `recurrent_kernel` weights matrix. Default: `None`.
  bias_constraint: Constraint function applied to the bias vector. Default:
    `None`.
  dropout: Float between 0 and 1. Fraction of the units to drop for the
    linear transformation of the inputs. Default: 0.
  recurrent_dropout: Float between 0 and 1. Fraction of the units to drop
    for the linear transformation of the recurrent state. Default: 0.

Call arguments:
  inputs: A 2D tensor, with shape of `[batch, feature]`.
  states: A 2D tensor with shape of `[batch, units]`, which is the state
    from the previous time step. For timestep 0, the initial state provided
    by user will be feed to cell.
  training: Python boolean indicating whether the layer should behave in
    training mode or in inference mode. Only relevant when `dropout` or
    `recurrent_dropout` is used.

Examples:

```python
inputs = np.random.random([32, 10, 8]).astype(np.float32)
rnn = tf.keras.layers.RNN(tf.keras.layers.SimpleRNNCell(4))

output = rnn(inputs)  # The output has shape `[32, 4]`.

rnn = tf.keras.layers.RNN(
    tf.keras.layers.SimpleRNNCell(4),
    return_sequences=True,
    return_state=True)

# whole_sequence_output has shape `[32, 10, 4]`.
# final_state has shape `[32, 4]`.
whole_sequence_output, final_state = rnn(inputs)
```
c                   > US::  a  [        SU S35      e[        R                  R                  R	                  5       (       a  UR                  SS5      U l        OUR                  SS5      U l        [        TU ]   " S	0 UD6  Xl	        [        R                  " U5      U l        X0l        [        R                  " U5      U l        [        R                  " U5      U l        [        R                  " U5      U l        [$        R                  " U5      U l        [$        R                  " U5      U l        [$        R                  " U	5      U l        [,        R                  " U
5      U l        [,        R                  " U5      U l        [,        R                  " U5      U l        [5        S[7        SU5      5      U l        [5        S[7        SU5      5      U l        U R                  U l        U R                  U l        g )
Nr   zQReceived an invalid value for argument `units`, expected a positive integer, got .enable_caching_deviceTFg      ?         ) 
ValueErrortfcompatv1#executing_eagerly_outside_functionspop_enable_caching_devicesuper__init__unitsr   get
activationuse_biasr   kernel_initializerrecurrent_initializerbias_initializerr   kernel_regularizerrecurrent_regularizerbias_regularizerr   kernel_constraintrecurrent_constraintbias_constraintminmaxdropoutrecurrent_dropout
state_sizeoutput_size)selfr!   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r0   r1   kwargs	__class__s                   \/home/james-whalen/.local/lib/python3.13/site-packages/tf_keras/src/layers/rnn/simple_rnn.pyr    SimpleRNNCell.__init__k   s   $ A:4497!= 
 99<<;;==*0**'+D' +1**'+D' 	"6"
%//*5 "."2"23E"F%1%5%56K%L" , 0 01A B"."2"23E"F%1%5%56K%L" , 0 01A B!,1B!C$/OO4H$I!*?3C 12!$S#c3D*E!F**::    c           	      :  > [         TU ]  U5        [        R                  " U 5      nU R	                  US   U R
                  4SU R                  U R                  U R                  US9U l	        U R	                  U R
                  U R
                  4SU R                  U R                  U R                  US9U l        U R                  (       aC  U R	                  U R
                  4SU R                  U R                   U R"                  US9U l        OS U l        SU l        g )Nkernel)shapenameinitializerregularizer
constraintcaching_devicerecurrent_kernelbiasT)r   buildr
   rB   
add_weightr!   r%   r(   r+   r<   r&   r)   r,   rC   r$   r'   r*   r-   rD   built)r4   input_shapedefault_caching_devicer6   s      r7   rE   SimpleRNNCell.build   s   k"!*!9!9$!?oor?DJJ/////--1 & 
 !%::tzz*#2222001 !0 !
 ==zzm 11 11//5 ( DI DI
r9   c                 l   [         R                  R                  U5      (       a  US   OUnU R                  X5      nU R	                  XC5      nUb$  [
        R                  " X-  U R                  5      nO [
        R                  " XR                  5      nU R                  b   [
        R                  " XpR                  5      nUb  XF-  nU[
        R                  " X@R                  5      -   nU R                  b  U R                  U5      n[         R                  R                  U5      (       a  U/OUn	X4$ )Nr   )r   nest	is_nestedget_dropout_mask_for_cell#get_recurrent_dropout_mask_for_cellr   dotr<   rD   bias_addrC   r#   )
r4   inputsstatestrainingprev_outputdp_maskrec_dp_maskhoutput	new_states
             r7   callSimpleRNNCell.call   s    #%77#4#4V#<#<fQi&00B>>
 F,dkk:AFKK0A99   II.A"%3KW[[.C.CDD??&__V,F " 1 1& 9 9VHv	  r9   c                 0    [         R                  " XX#5      $ N)r
   #generate_zero_filled_state_for_cell)r4   rR   
batch_sizedtypes       r7   get_initial_stateSimpleRNNCell.get_initial_state   s    <<*
 	
r9   c                   > U R                   [        R                  " U R                  5      U R                  [
        R                  " U R                  5      [
        R                  " U R                  5      [
        R                  " U R                  5      [        R                  " U R                  5      [        R                  " U R                  5      [        R                  " U R                  5      [        R                  " U R                  5      [        R                  " U R                  5      [        R                  " U R                   5      U R"                  U R$                  S.nUR'                  [(        R*                  " U 5      5        [,        TU ]]  5       n[1        [3        UR5                  5       5      [3        UR5                  5       5      -   5      $ )N)r!   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r0   r1   )r!   r   	serializer#   r$   r   r%   r&   r'   r   r(   r)   r*   r   r+   r,   r-   r0   r1   updater
    config_for_enable_caching_devicer   
get_configdictlistitemsr4   configbase_configr6   s      r7   rh   SimpleRNNCell.get_config   sV   ZZ%//@"."8"8''# &2%;%;**& !- 6 6t7L7L M"."8"8''# &2%;%;**& !- 6 6t7L7L M!,!6!6t7M7M!N$/$9$9))%  +44T5I5IJ||!%!7!71
4 	i@@FGg(*D**,-V\\^0DDEEr9   )r   r#   rD   r-   r'   r*   rG   r0   r<   r+   r%   r(   r3   r,   r1   r&   rC   r)   r2   r!   r$   )tanhTglorot_uniform
orthogonalzerosNNNNNNr   r   r^   NNN)__name__
__module____qualname____firstlineno____doc__r    r   shape_type_conversionrE   r[   rb   rh   __static_attributes____classcell__r6   s   @r7   r   r   %   sj    BN +* "!4&l ## $@!.

F Fr9   r   zkeras.layers.SimpleRNNc                   b  ^  \ rS rSrSr                   SU 4S jjrSU 4S jjr\S 5       r\S 5       r	\S 5       r
\S 5       r\S	 5       r\S
 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       rU 4S jr\S 5       rSrU =r$ )	SimpleRNN   a  Fully-connected RNN where the output is to be fed back to input.

See
[the TF-Keras RNN API guide](https://www.tensorflow.org/guide/tf_keras/rnn)
for details about the usage of RNN API.

Args:
  units: Positive integer, dimensionality of the output space.
  activation: Activation function to use.
    Default: hyperbolic tangent (`tanh`).
    If you pass None, no activation is applied
    (ie. "linear" activation: `a(x) = x`).
  use_bias: Boolean, (default `True`), whether the layer uses a bias vector.
  kernel_initializer: Initializer for the `kernel` weights matrix,
    used for the linear transformation of the inputs. Default:
    `glorot_uniform`.
  recurrent_initializer: Initializer for the `recurrent_kernel`
    weights matrix, used for the linear transformation of the recurrent
    state.  Default: `orthogonal`.
  bias_initializer: Initializer for the bias vector. Default: `zeros`.
  kernel_regularizer: Regularizer function applied to the `kernel` weights
    matrix. Default: `None`.
  recurrent_regularizer: Regularizer function applied to the
    `recurrent_kernel` weights matrix. Default: `None`.
  bias_regularizer: Regularizer function applied to the bias vector.
    Default: `None`.
  activity_regularizer: Regularizer function applied to the output of the
    layer (its "activation"). Default: `None`.
  kernel_constraint: Constraint function applied to the `kernel` weights
    matrix. Default: `None`.
  recurrent_constraint: Constraint function applied to the
    `recurrent_kernel` weights matrix.  Default: `None`.
  bias_constraint: Constraint function applied to the bias vector. Default:
    `None`.
  dropout: Float between 0 and 1.
    Fraction of the units to drop for the linear transformation of the
    inputs. Default: 0.
  recurrent_dropout: Float between 0 and 1.
    Fraction of the units to drop for the linear transformation of the
    recurrent state. Default: 0.
  return_sequences: Boolean. Whether to return the last output
    in the output sequence, or the full sequence. Default: `False`.
  return_state: Boolean. Whether to return the last state
    in addition to the output. Default: `False`
  go_backwards: Boolean (default False).
    If True, process the input sequence backwards and return the
    reversed sequence.
  stateful: Boolean (default False). If True, the last state
    for each sample at index i in a batch will be used as initial
    state for the sample of index i in the following batch.
  unroll: Boolean (default False).
    If True, the network will be unrolled,
    else a symbolic loop will be used.
    Unrolling can speed-up a RNN,
    although it tends to be more memory-intensive.
    Unrolling is only suitable for short sequences.

Call arguments:
  inputs: A 3D tensor, with shape `[batch, timesteps, feature]`.
  mask: Binary tensor of shape `[batch, timesteps]` indicating whether
    a given timestep should be masked. An individual `True` entry indicates
    that the corresponding timestep should be utilized, while a `False`
    entry indicates that the corresponding timestep should be ignored.
  training: Python boolean indicating whether the layer should behave in
    training mode or in inference mode. This argument is passed to the cell
    when calling it. This is only relevant if `dropout` or
    `recurrent_dropout` is used.
  initial_state: List of initial state tensors to be passed to the first
    call of the cell.

Examples:

```python
inputs = np.random.random([32, 10, 8]).astype(np.float32)
simple_rnn = tf.keras.layers.SimpleRNN(4)

output = simple_rnn(inputs)  # The output has shape `[32, 4]`.

simple_rnn = tf.keras.layers.SimpleRNN(
    4, return_sequences=True, return_state=True)

# whole_sequence_output has shape `[32, 10, 4]`.
# final_state has shape `[32, 4]`.
whole_sequence_output, final_state = simple_rnn(inputs)
```
c           	        > SU;   a'  UR                  S5        [        R                  " S5        SU;   a  SUR                  S5      0nO0 n[        U40 SU_SU_SU_SU_SU_S	U_S
U_SU	_SU_SU_SU_SU_SU_SUR	                  S5      _SUR	                  SS5      _SS_UD6n[
        TU ]  " U4UUUUUS.UD6  [        R                  " U
5      U l        [        SS9/U l
        g )NimplementationzhThe `implementation` argument in `SimpleRNN` has been deprecated. Please remove it from your layer call.r   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r0   r1   ra   	trainableTr>   simple_rnn_cell)return_sequencesreturn_statego_backwardsstatefulunroll   )ndim)r   loggingwarningr   r"   r   r    r   activity_regularizerr	   
input_spec)r4   r!   r#   r$   r%   r&   r'   r(   r)   r*   r   r+   r,   r-   r0   r1   r   r   r   r   r   r5   cell_kwargscellr6   s                           r7   r    SimpleRNN.__init__W  si   0 v%JJ'(OO9
 #f,'4K)LK K
!
 
  2	

 #8
 .
  2
 #8
 .
 0
 "6
 ,
 
 0
 **W%
  jjd3!
" #%
( 		
-%%	
 	
 %1$4$45I$J!$!,-r9   c                     > [         TU ]  XX4S9$ )N)maskrT   initial_state)r   r[   )r4   rR   r   rT   r   r6   s        r7   r[   SimpleRNN.call  s    w|  
 	
r9   c                 .    U R                   R                  $ r^   )r   r!   r4   s    r7   r!   SimpleRNN.units  s    yyr9   c                 .    U R                   R                  $ r^   )r   r#   r   s    r7   r#   SimpleRNN.activation  s    yy###r9   c                 .    U R                   R                  $ r^   )r   r$   r   s    r7   r$   SimpleRNN.use_bias  s    yy!!!r9   c                 .    U R                   R                  $ r^   )r   r%   r   s    r7   r%   SimpleRNN.kernel_initializer      yy+++r9   c                 .    U R                   R                  $ r^   )r   r&   r   s    r7   r&   SimpleRNN.recurrent_initializer      yy...r9   c                 .    U R                   R                  $ r^   )r   r'   r   s    r7   r'   SimpleRNN.bias_initializer      yy)))r9   c                 .    U R                   R                  $ r^   )r   r(   r   s    r7   r(   SimpleRNN.kernel_regularizer  r   r9   c                 .    U R                   R                  $ r^   )r   r)   r   s    r7   r)   SimpleRNN.recurrent_regularizer  r   r9   c                 .    U R                   R                  $ r^   )r   r*   r   s    r7   r*   SimpleRNN.bias_regularizer  r   r9   c                 .    U R                   R                  $ r^   )r   r+   r   s    r7   r+   SimpleRNN.kernel_constraint      yy***r9   c                 .    U R                   R                  $ r^   )r   r,   r   s    r7   r,   SimpleRNN.recurrent_constraint  s    yy---r9   c                 .    U R                   R                  $ r^   )r   r-   r   s    r7   r-   SimpleRNN.bias_constraint  s    yy(((r9   c                 .    U R                   R                  $ r^   )r   r0   r   s    r7   r0   SimpleRNN.dropout  s    yy   r9   c                 .    U R                   R                  $ r^   )r   r1   r   s    r7   r1   SimpleRNN.recurrent_dropout  r   r9   c                   > U R                   [        R                  " U R                  5      U R                  [
        R                  " U R                  5      [
        R                  " U R                  5      [
        R                  " U R                  5      [        R                  " U R                  5      [        R                  " U R                  5      [        R                  " U R                  5      [        R                  " U R                  5      [        R                  " U R                  5      [        R                  " U R                   5      [        R                  " U R"                  5      U R$                  U R&                  S.n[(        TU ]U  5       nUR-                  [.        R0                  " U R2                  5      5        US	 [5        [7        UR9                  5       5      [7        UR9                  5       5      -   5      $ )N)r!   r#   r$   r%   r&   r'   r(   r)   r*   r   r+   r,   r-   r0   r1   r   )r!   r   re   r#   r$   r   r%   r&   r'   r   r(   r)   r*   r   r   r+   r,   r-   r0   r1   r   rh   rf   r
   rg   r   ri   rj   rk   rl   s      r7   rh   SimpleRNN.get_config  s{   ZZ%//@"."8"8''# &2%;%;**& !- 6 6t7L7L M"."8"8''# &2%;%;**& !- 6 6t7L7L M$0$:$:))% "-!6!6t7M7M!N$/$9$9))%  +44T5I5IJ||!%!7!77
: g(*i@@KLD**,-V\\^0DDEEr9   c                 @    SU;   a  UR                  S5        U " S0 UD6$ )Nr   r   )r   )clsrm   s     r7   from_configSimpleRNN.from_config  s#    v%JJ'(}V}r9   )r   r   )rp   Trq   rr   rs   NNNNNNNr   r   FFFFFrt   )ru   rv   rw   rx   ry   r    r[   propertyr!   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r0   r1   rh   classmethodr   r{   r|   r}   s   @r7   r   r      s   Ut +* "!!+C.J

   $ $ " " , , / / * * , , / / * * + + . . ) ) ! ! + +!FF  r9   r   )ry   tensorflow.compat.v2r   v2r   tf_keras.srcr   r   r   r   r   tf_keras.src.enginer   tf_keras.src.engine.input_specr	   tf_keras.src.layers.rnnr
    tf_keras.src.layers.rnn.base_rnnr   .tf_keras.src.layers.rnn.dropout_rnn_cell_mixinr   tf_keras.src.utilsr   tensorflow.python.platformr   r    tensorflow.python.util.tf_exportr   BaseRandomLayerr   r   r   r9   r7   <module>r      s    ! " ! $   $ % % * 4 - 0 N ' = 9 *+UF')C)C UF ,UFp &'A A (Ar9   