
    6bi=                         S 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9 " S S\	R$                  5      5       r\" S/S9 " S S\5      5       rg)zGated Recurrent Unit V1 layer.    )activations)constraints)initializers)regularizers)	InputSpec)gru)	rnn_utils)RNN)
tf_logging)keras_exportzkeras.layers.GRUCell)v1c                   N   ^  \ rS rSrSr               SU 4S jjrSrU =r$ )GRUCell    a$  Cell class for the GRU layer.

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`).
  recurrent_activation: Activation function to use
    for the recurrent step.
    Default: hard sigmoid (`hard_sigmoid`).
    If you pass `None`, no activation is applied
    (ie. "linear" activation: `a(x) = x`).
  use_bias: Boolean, whether the layer uses a bias vector.
  kernel_initializer: Initializer for the `kernel` weights matrix,
    used for the linear transformation of the inputs.
  recurrent_initializer: Initializer for the `recurrent_kernel`
    weights matrix,
    used for the linear transformation of the recurrent state.
  bias_initializer: Initializer for the bias vector.
  kernel_regularizer: Regularizer function applied to
    the `kernel` weights matrix.
  recurrent_regularizer: Regularizer function applied to
    the `recurrent_kernel` weights matrix.
  bias_regularizer: Regularizer function applied to the bias vector.
  kernel_constraint: Constraint function applied to
    the `kernel` weights matrix.
  recurrent_constraint: Constraint function applied to
    the `recurrent_kernel` weights matrix.
  bias_constraint: Constraint function applied to the bias vector.
  dropout: Float between 0 and 1. Fraction of the units to drop for the
    linear transformation of the inputs.
  recurrent_dropout: Float between 0 and 1.
    Fraction of the units to drop for
    the linear transformation of the recurrent state.
  reset_after: GRU convention (whether to apply reset gate after or
    before matrix multiplication). False = "before" (default),
    True = "after" (cuDNN compatible).

Call arguments:
  inputs: A 2D tensor.
  states: List of state tensors corresponding to the previous timestep.
  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.
c           	         > [         TU ]  " 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_SUR                  SS5      _SU_UD6  g )N
activationrecurrent_activationuse_biaskernel_initializerrecurrent_initializerbias_initializerkernel_regularizerrecurrent_regularizerbias_regularizerkernel_constraintrecurrent_constraintbias_constraintdropoutrecurrent_dropoutimplementation   reset_after)super__init__pop)selfunitsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r"   kwargs	__class__s                     X/home/james-whalen/.local/lib/python3.13/site-packages/tf_keras/src/layers/rnn/gru_v1.pyr$   GRUCell.__init__Q   s    ( 		
!	
 "6	
 		

  2	
 #8	
 .	
  2	
 #8	
 .	
 0	
 "6	
 ,	
 	
 0	
  "::&6:!	
" $%	
     )tanhhard_sigmoidTglorot_uniform
orthogonalzerosNNNNNN        r3   F)__name__
__module____qualname____firstlineno____doc__r$   __static_attributes____classcell__r)   s   @r*   r   r       sB    -d ++* "!#'
 '
r,   r   zkeras.layers.GRUc                     ^  \ 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\S 5       r\S 5       r\S 5       rU 4S jr\S 5       rSrU =r$ )GRU{   a  Gated Recurrent Unit - Cho et al. 2014.

There are two variants. The default one is based on 1406.1078v3 and
has reset gate applied to hidden state before matrix multiplication. The
other one is based on original 1406.1078v1 and has the order reversed.

The second variant is compatible with CuDNNGRU (GPU-only) and allows
inference on CPU. Thus it has separate biases for `kernel` and
`recurrent_kernel`. Use `'reset_after'=True` and
`recurrent_activation='sigmoid'`.

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`).
  recurrent_activation: Activation function to use
    for the recurrent step.
    Default: hard sigmoid (`hard_sigmoid`).
    If you pass `None`, no activation is applied
    (ie. "linear" activation: `a(x) = x`).
  use_bias: Boolean, whether the layer uses a bias vector.
  kernel_initializer: Initializer for the `kernel` weights matrix,
    used for the linear transformation of the inputs.
  recurrent_initializer: Initializer for the `recurrent_kernel` weights
    matrix, used for the linear transformation of the recurrent state.
  bias_initializer: Initializer for the bias vector.
  kernel_regularizer: Regularizer function applied to
    the `kernel` weights matrix.
  recurrent_regularizer: Regularizer function applied to
    the `recurrent_kernel` weights matrix.
  bias_regularizer: Regularizer function applied to the bias vector.
  activity_regularizer: Regularizer function applied to
    the output of the layer (its "activation")..
  kernel_constraint: Constraint function applied to
    the `kernel` weights matrix.
  recurrent_constraint: Constraint function applied to
    the `recurrent_kernel` weights matrix.
  bias_constraint: Constraint function applied to the bias vector.
  dropout: Float between 0 and 1.
    Fraction of the units to drop for
    the linear transformation of the inputs.
  recurrent_dropout: Float between 0 and 1.
    Fraction of the units to drop for
    the linear transformation of the recurrent state.
  return_sequences: Boolean. Whether to return the last output
    in the output sequence, or the full sequence.
  return_state: Boolean. Whether to return the last state
    in addition to the output.
  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.
  time_major: The shape format of the `inputs` and `outputs` tensors.
    If True, the inputs and outputs will be in shape
    `(timesteps, batch, ...)`, whereas in the False case, it will be
    `(batch, timesteps, ...)`. Using `time_major = True` is a bit more
    efficient because it avoids transposes at the beginning and end of the
    RNN calculation. However, most TensorFlow data is batch-major, so by
    default this function accepts input and emits output in batch-major
    form.
  reset_after: GRU convention (whether to apply reset gate after or
    before matrix multiplication). False = "before" (default),
    True = "after" (cuDNN compatible).

Call arguments:
  inputs: A 3D tensor.
  mask: Binary tensor of shape `(samples, 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.
c           	        > UR                  SS5      nUS:X  a  [        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_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 )Nr    r!   r   zm`implementation=0` has been deprecated, and now defaults to `implementation=1`.Please update your layer call.enable_caching_devicer   r   r   r   r   r   r   r   r   r   r   r   r   r   r"   dtype	trainableTnamegru_cell)return_sequencesreturn_statego_backwardsstatefulunroll   )ndim)r%   loggingwarningr   getr#   r$   r   activity_regularizerr   
input_spec)r&   r'   r   r   r   r   r   r   r   r   r   rO   r   r   r   r   r   rE   rF   rG   rH   rI   r"   r(   r    cell_kwargscellr)   s                              r*   r$   GRU.__init__   s   4  $4a8QOO1
 #f,'4K)LK K
!
 "6
 	

  2
 #8
 .
  2
 #8
 .
 0
 "6
 ,
 
 0
  *!
" $#
$ **W%%
& jjd3'
( +
. 		
-%%	
 	
 %1$4$45I$J!$!,-r,   c                     > [         TU ]  XX4S9$ )N)masktraininginitial_state)r#   call)r&   inputsrU   rV   rW   r)   s        r*   rX   GRU.call  s    w|  
 	
r,   c                 .    U R                   R                  $ N)rR   r'   r&   s    r*   r'   	GRU.units$  s    yyr,   c                 .    U R                   R                  $ r\   )rR   r   r]   s    r*   r   GRU.activation(  s    yy###r,   c                 .    U R                   R                  $ r\   )rR   r   r]   s    r*   r   GRU.recurrent_activation,      yy---r,   c                 .    U R                   R                  $ r\   )rR   r   r]   s    r*   r   GRU.use_bias0  s    yy!!!r,   c                 .    U R                   R                  $ r\   )rR   r   r]   s    r*   r   GRU.kernel_initializer4      yy+++r,   c                 .    U R                   R                  $ r\   )rR   r   r]   s    r*   r   GRU.recurrent_initializer8      yy...r,   c                 .    U R                   R                  $ r\   )rR   r   r]   s    r*   r   GRU.bias_initializer<      yy)))r,   c                 .    U R                   R                  $ r\   )rR   r   r]   s    r*   r   GRU.kernel_regularizer@  rh   r,   c                 .    U R                   R                  $ r\   )rR   r   r]   s    r*   r   GRU.recurrent_regularizerD  rk   r,   c                 .    U R                   R                  $ r\   )rR   r   r]   s    r*   r   GRU.bias_regularizerH  rn   r,   c                 .    U R                   R                  $ r\   )rR   r   r]   s    r*   r   GRU.kernel_constraintL      yy***r,   c                 .    U R                   R                  $ r\   )rR   r   r]   s    r*   r   GRU.recurrent_constraintP  rc   r,   c                 .    U R                   R                  $ r\   )rR   r   r]   s    r*   r   GRU.bias_constraintT  s    yy(((r,   c                 .    U R                   R                  $ r\   )rR   r   r]   s    r*   r   GRU.dropoutX  s    yy   r,   c                 .    U R                   R                  $ r\   )rR   r   r]   s    r*   r   GRU.recurrent_dropout\  rw   r,   c                 .    U R                   R                  $ r\   )rR   r    r]   s    r*   r    GRU.implementation`  s    yy'''r,   c                 .    U R                   R                  $ r\   )rR   r"   r]   s    r*   r"   GRU.reset_afterd  s    yy$$$r,   c                   > 0 SU R                   _S[        R                  " U R                  5      _S[        R                  " U R                  5      _SU R
                  _S[        R                  " U R                  5      _S[        R                  " U R                  5      _S[        R                  " U R                  5      _S[        R                  " U R                  5      _S	[        R                  " U R                  5      _S
[        R                  " U R                  5      _S[        R                  " U R                  5      _S[        R                  " U R                   5      _S[        R                  " U R"                  5      _S[        R                  " U R$                  5      _SU R&                  _SU R(                  _SU R*                  _SU R,                  0EnUR/                  [0        R2                  " U R4                  5      5        [6        TU ]q  5       nUS	 [;        [=        UR?                  5       5      [=        UR?                  5       5      -   5      $ )Nr'   r   r   r   r   r   r   r   r   r   rO   r   r   r   r   r   r    r"   rR   ) r'   r   	serializer   r   r   r   r   r   r   r   r   r   r   rO   r   r   r   r   r   r   r    r"   updater	    config_for_enable_caching_devicerR   r#   
get_configdictlistitems)r&   configbase_configr)   s      r*   r   GRU.get_configh  s9   !
TZZ!
+//@!
 #K$9$9))%!
 !
 !,"8"8''#!
 $\%;%;**&!
  6 6t7L7L M!
 !,"8"8''#!
" $\%;%;**&#!
(  6 6t7L7L M)!
* #L$:$:))%+!
0  !6!6t7M7M!N1!
2 #K$9$9))%3!
8 {44T5I5IJ9!
: t||;!
<  !7!7=!
> d11?!
@ 4++A!
D 	i@@KLg(*D**,-V\\^0DDEEr,   c                 :    SU;   a  US   S:X  a  SUS'   U " S0 UD6$ )Nr    r   r!   r-   r-   )clsr   s     r*   from_configGRU.from_config  s.    v%&1A*Ba*G'(F#$}V}r,   )rO   rP   )r.   r/   Tr0   r1   r2   NNNNNNNr3   r3   FFFFFF)NNN)r4   r5   r6   r7   r8   r$   rX   propertyr'   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r"   r   classmethodr   r9   r:   r;   s   @r*   r=   r=   {   s   Vv ++* "!!/H.T

   $ $ . . " " , , / / * * , , / / * * + + . . ) ) ! ! + + ( ( % %&FP  r,   r=   N)r8   tf_keras.srcr   r   r   r   tf_keras.src.engine.input_specr   tf_keras.src.layers.rnnr   r	    tf_keras.src.layers.rnn.base_rnnr
   tensorflow.python.platformr   rL    tensorflow.python.util.tf_exportr   r   r=   r-   r,   r*   <module>r      s    % % $ % % 4 ' - 0 = 9 ()*W
ckk W
 +W
t $%&X# X 'Xr,   