
    ij                         d dl Zd dlmZ 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 ddZd Zd Zd Zd Z	dd	Z
d
 Zd Zd Zd Z	 ddZ	 	 	 	 ddZd Zd Zd Zy)    N)treec           	      .   	
*+,-./01234 xs j                   d   d }|st        j                  |      t        j                        }|d   j                   d   }|t	        j                   |d         d   n|4|D ]  }|j                   j                  d        |z|j                  t        j                  k7  r$t	        j                  |t        j                        }t        |j                         dk(  rt	        j                  |d      }|s ||      }g d'd	*|r|st        d
      t              }g }g }fd}t        j                        rt        j                  |      2n	 |      f22fd}|t	        j                  |      }r|j                          t!        |      D ]  } ||      }||   .  |t        |      t              z         \  }} *.|      }|st	        j"                  |      }n|d   }t	        j$                  |||      }t        j                  |      }t        j                  |      }t        *.fd|D              }t        d t'        |||      D              }t        j(                  ||      }
r$|j+                  |       |j+                  |       |g}|g} |d   }|d   }t	        j,                  |      }	rt	        j$                   *|d   |      |t	        j"                  |            }t	        j$                   *||d      |t	        j"                  |            }nt!        |      D ]V  } ||      }  |t        |      t              z         \  }}
r#|j+                  |       |j+                  |       Q|g}|g}X |d   }|d   }t	        j,                  |      }nt              }t        4fdt/        |      D              -t        fdt'        -|      D              -t        j(                  |D cg c]  }|d   	 c}      }   | t              t              z         \  }!}"
r4nd1t        1fdt/        t        j                  |!            D              }#t	        j0                  ddd      }$4}%nt	        j2                        }%4fd|%ddd}&|[rt	        j                  |dg      }t	        j4                  t        j                  4d      //j                  |      //fd0*fd+n]t7        t        j8                        rAr6t	        j2                  d      }'t	        j:                  |'dz
        33fd0nfd0d  +nd00Vt        d! t        j                  |!      D              ,+,-0
 	f	d"}(t	        j<                  d(|(|$|#,f|z   d#|&})|)dd }n,-
 fd$}(t	        j<                  d(|(|$|#f|z   d#|&})|)dd }|)d   }#t        d% |#D              }t        d& |D              }t        j(                  |!|      }t        j(                  |!|      }|st        j                  ||      }|||fS c c}w ))aS  Iterates over the time dimension of a tensor.

    Args:
        step_function: RNN step function.
            Args;
                `input`; Tensor with shape `(samples, ...)` (no time dimension),
                    representing input for the batch of samples at a certain
                    time step.
                `states`; List of tensors.
            Returns;
                `output`; Tensor with shape `(samples, output_dim)`
                    (no time dimension).
                `new_states`; List of tensors, same length and shapes
                    as 'states'. The first state in the list must be the
                    output tensor at the previous timestep.
        inputs: Tensor of temporal data of shape `(samples, time, ...)`
            (at least 3D), or nested tensors, and each of which has shape
            `(samples, time, ...)`.
        initial_states: Tensor with shape `(samples, state_size)`
            (no time dimension), containing the initial values for the states
            used in the step function. In the case that state_size is in a
            nested shape, the shape of initial_states will also follow the
            nested structure.
        go_backwards: Boolean. If `True`, do the iteration over the time
            dimension in reverse order and return the reversed sequence.
        mask: Binary tensor with shape `(samples, time, 1)`,
            with a zero for every element that is masked.
        constants: List of constant values passed at each step.
        unroll: Whether to unroll the RNN or to use a symbolic `while_loop`.
        input_length: An integer or a 1-D Tensor, depending on whether
            the time dimension is fixed-length or not. In case of variable
            length input, it is used for masking in case there's no mask
            specified.
        time_major: Boolean. 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.
        zero_output_for_mask: Boolean. If `True`, the output for masked timestep
            will be zeros, whereas in the `False` case, output from previous
            timestep is returned.
        return_all_outputs: Boolean. If `True`, return the recurrent outputs for
            all timesteps in the sequence. If `False`, only return the output
            for the last timestep (which consumes less memory).

    Returns:
        A tuple, `(last_output, outputs, new_states)`.
            - `last_output`: the latest output of the rnn,
                with shape `(samples, ...)`.
            - `outputs`:
                - If `return_all_outputs=True`: a tensor with shape
                  `(samples, time, ...)` where each entry `outputs[s, t]` is the
                  output of the step function at time `t` for sample `s`
                - Else, a tensor equal to `last_output` with shape
                  `(samples, 1, ...)`
            - `new_states`: list of tensors, latest states returned by
                the step function, of shape `(samples, ...)`.
       c                     t        t        t        | j                                    }d\  |d<   |d<   t	        j
                  | |      S )Nr   r   r   r   )listrangelenshapetf	transpose)input_taxess     u/var/www/html/emotional.easysim.app/public_html/venv/lib/python3.12/site-packages/keras/src/backend/tensorflow/rnn.pyswap_batch_timestepz rnn.<locals>.swap_batch_timestepQ   s=    E#gmm,-.Qa||GT**    r   N      axisc                    t        j                  |       rt        d|        t        j                  |      rt        d|       t        |j                        t        | j                        z
  }t        |      D ]  }t        j                  | d      }  dg|z  |j                  j                         |d  z   }t        j                  | |      S )Nz)mask_t is expected to be tensor, but got z*input_t is expected to be tensor, but got r   r   )
r   	is_nested
ValueErrorr
   r   r	   r   expand_dimsas_listtile)mask_tr   	fixed_dim	rank_diff_	multipless         r   _expand_maskzrnn.<locals>._expand_maskt   s    >>&!;F8D  >>'"<WIF  &V\\)::	y! 	0A^^FB/F	0C)Ogmm&;&;&=ij&II	wwvy))r   z/Unrolling requires a fixed number of timesteps.c                 V    t        j                  |       } r| j                          | S N)r   unstackreverse)r   go_backwardss    r   _process_single_input_tz$rnn.<locals>._process_single_input_t   s#    jj)G!Nr   c                 ^    D cg c]  }||    	 }}t        j                  |      S c c}w r%   )r   pack_sequence_as)timet_inpinputsprocessed_inputs      r   _get_input_tensorzrnn.<locals>._get_input_tensor   s2    &562d86C6((55 7s   *c              3   0   K   | ]  } |        y wr%    ).0sr#   r   s     r   	<genexpr>zrnn.<locals>.<genexpr>   s      %01L+%s   c              3   R   K   | ]  \  }}}t        j                  |||       ! y wr%   r   where)r4   mr5   pss       r   r6   zrnn.<locals>.<genexpr>   s+      * 1b HHQ2&*   %'r   c              3   n   K   | ],  \  }}t        j                  |j                  d |        . yw)	input_ta_dtypesizetensor_array_nameN)r   TensorArrayrA   )r4   ir.   time_steps_ts      r   r6   zrnn.<locals>.<genexpr>   s@      
 3 NNii!$-aS/ 
s   25c              3      K   | ]@  \  }}s|j                  |      n%|j                  t        j                  |d g             B yw)r   N)r&   r   r'   )r4   tainput_r(   s      r   r6   zrnn.<locals>.<genexpr>   sK      
 F $ 

6"ZZ

6A3 789
s   AA	c              3      K   | ]7  \  }}t        j                  |j                  |j                  d |        9 yw)
output_ta_)rA   rB   element_shaperC   N)r   rD   rA   r   )r4   rE   outoutput_ta_sizes      r   r6   zrnn.<locals>.<genexpr>  sH      
 3 NNii#!ii$.qc"2	 
s   =A int32r,   )rA   namec                     | k  S r%   r3   )r,   r!   rF   s     r   <lambda>zrnn.<locals>.<lambda>  s    TL%8 r       T)condmaximum_iterationsparallel_iterationsswap_memorymask_tar@   c                 &    j                  |       S r%   read)r,   rX   s    r   
masking_fnzrnn.<locals>.masking_fn+  s    ||D))r   c                 j     t         fd|D              }t        d t        |||      D              S )Nc              3   Z   K   | ]"  } |t        j                                $ yw)r=   N)r
   r   )r4   or#   r   s     r   r6   z5rnn.<locals>.compute_masked_output.<locals>.<genexpr>/  s.      % !c&,,6GHH%s   (+c              3   R   K   | ]  \  }}}t        j                  |||       ! y wr%   r8   )r4   r:   r_   fms       r   r6   z5rnn.<locals>.compute_masked_output.<locals>.<genexpr>3  s+       1b HHQ2&r<   tuplezip)r   flat_out	flat_masktiled_mask_tr#   s   `   r   compute_masked_outputz"rnn.<locals>.compute_masked_output.  s?    $ %%%    $'h	$J  r   c                 0    t        j                  |       S r%   )r   less)r,   rev_input_lengths    r   r\   zrnn.<locals>.masking_fn=  s    77#3T::r   c                 0    t        j                  |       S r%   )r   greater)r,   input_lengths    r   r\   zrnn.<locals>.masking_fnB  s    ::lD99r   c                 @     t         fdt        ||      D              S )Nc              3   R   K   | ]  \  }}t        j                  ||         y wr%   r8   )r4   r_   zor   s      r   r6   z5rnn.<locals>.compute_masked_output.<locals>.<genexpr>F  s*      B HHVQ+s   $'rb   )r   re   rf   s   `  r   rh   z"rnn.<locals>.compute_masked_outputE  s$     #&x#;  r   c              3   F   K   | ]  }t        j                  |        y wr%   )r   
zeros_liker4   r_   s     r   r6   zrnn.<locals>.<genexpr>Q  s      %%&a %s   !c                 4  	  t         fdD              }t        j                  |      }        } |t        |      t              z         \  }}t        j                  |      }rnt        j                  |      }	 |||	      }
t        j                  |      }t        j                  |      } |||      }t        j                  ||      }r ndt        fdt	        ||
      D              } dz   |t        |
      ft        |      z   S )as  RNN step function.

                Args:
                    time: Current timestep value.
                    output_ta_t: TensorArray.
                    prev_output: tuple of outputs from time - 1.
                    *states: List of states.

                Returns:
                    Tuple: `(time + 1, output_ta_t, output) + tuple(new_states)`
                c              3   @   K   | ]  }|j                          y wr%   rZ   r4   rH   r,   s     r   r6   z%rnn.<locals>._step.<locals>.<genexpr>a       %Gbggdm%G   r   c              3   H   K   | ]  \  }}|j                  |        y wr%   writer4   rH   rM   ta_index_to_writes      r   r6   z%rnn.<locals>._step.<locals>.<genexpr>|  )      $C HH.4$   "r   rc   r   r+   flattenrd   )r,   output_ta_tprev_outputstatescurrent_inputr   output
new_statesflat_outputflat_mask_outputflat_new_output
flat_stateflat_new_stateflat_final_stater~   rh   	constantsflat_zero_outputinput_tar/   r\   return_all_outputsstep_functionzero_output_for_masks   `             @r   _stepzrnn.<locals>._stepU  s)    !&%Gh%G G $ 5 5fm L#D)%2!5=53C#C&"
 #ll62 , %k2 !
 #8K)9#
 "\\&1
!%j!9#8NJ$  "22:?OP
,>DA!# $#&{O#D$ 
 q+u_/EFJ  r   )body	loop_varsc                     t         fdD              }t        j                  |      } |t        |      t        	      z         \  }}t        j                  |      }t        j                  |      }r ndt        fdt	        ||      D              }t        j                  
|      } dz   |ft        |      z   S )a)  RNN step function.

                Args:
                    time: Current timestep value.
                    output_ta_t: TensorArray.
                    *states: List of states.

                Returns:
                    Tuple: `(time + 1,output_ta_t) + tuple(new_states)`
                c              3   @   K   | ]  }|j                          y wr%   rZ   rw   s     r   r6   z%rnn.<locals>._step.<locals>.<genexpr>  rx   ry   r   c              3   H   K   | ]  \  }}|j                  |        y wr%   r{   r}   s      r   r6   z%rnn.<locals>._step.<locals>.<genexpr>  r   r   r   r   )r,   r   r   r   r   r   r   r   r~   r   initial_statesr   r/   r   r   s   `       @r   r   zrnn.<locals>._step  s     !&%Gh%G G $ 5 5fm L%2!5=53C#C&"
 "&j!9"ll62,>DA!# $#&{K#@$ 
 "22"N
 q+.z1BBBr   c              3   <   K   | ]  }|j                           y wr%   )stackrt   s     r   r6   zrnn.<locals>.<genexpr>  s     5a	5s   c              3   &   K   | ]	  }|d      yw)r   Nr3   rt   s     r   r6   zrnn.<locals>.<genexpr>  s     3aAbE3s   )r   r3   )r   r   map_structurer   r   with_rank_at_leastrA   boolcastr
   r   r   rc   r   r&   r'   r	   rs   r9   rd   r+   appendr   	enumerateconstant
reduce_maxrD   
isinstanceTensorsubtract
while_loop)5r   r/   r   r(   maskr   unrollrn   
time_majorr   r   r   flattened_inputs
time_stepsrI   r   successive_statessuccessive_outputsr)   r1   	mask_listrE   r.   r   r   rg   r   flat_statesflat_new_statesflat_final_stateslast_outputoutputsinput_time_zerooutput_time_zeror!   	output_tar,   max_iterationswhile_loop_kwargsmax_lenr   final_outputsr#   rh   r   r   r   rX   r\   rN   r0   rk   rF   s5   ```` ` ` ``                               @@@@@@@@@@@r   rnnr      s   R  26<<?L+ ##$7@||F+!!$**1-J,6,>!!$%a(J  # +''*+ :: 774)Dtzz?a>>$R0D&t,D	* NOO~&	 >>&!"00'O  7v>@O	6 

4(I!!#:& !1'*"1%2vy)99&"
  ,FF;)"$--"7K"4R"8K,D"ll62"&,,z":$ %5@%   %* *$'$o{%* %! ..v7HI%&--f5%,,V4*0&)/%C!1D -R0K*2.Jhh12G# hh 2<MM+.
 (( w!<MM'* :& 
1'*!.vy)99" &&--f5%,,V4*0&)/%
1 -R0K*2.Jhh12G ~&
  
 $$45
 
  
 "(,<=
 
 //'78SV8

 ,U>2U95EE
! *< 
 $DLL1A$BC
 
	 {{1G&9)N]]<8N 9"0#%	
 zz$,nnggLIG ood+G* bii0--1=#%;;w{L#I ;
: J!  % %*.,,7G*H%  . .` MM ,<=F $M 'qr*JC C< MM +f4 $M
 'qr*J!!$	59553733''(8'B++,<kJ$$%8'B++y 9s   <Z
c                    t        |||
|d u|      }|st        ddlm} t	        ||      r|j
                  }t	        ||      r|j
                  }t	        ||      r|j
                  }	 t        | |||||||	|	      S # t        j                  j                  $ r t        t        j                  j                  $ r t        w xY w)N)use_biasreset_afterr   Variable)cudnn_okNotImplementedErrorkeras.src.backend.tensorflowr   r   value
_cudnn_grur   errorsInvalidArgumentErrorNotFoundError)r/   initial_stater   kernelrecurrent_kernelbias
activationrecurrent_activationreturn_sequencesr(   r   r   r   cudnn_supportedr   s                  r   grur     s     T!O !!5&(#"H-+11$!zz"

 
	
 99)) "!!99"" "!!"s   *A= =ACc                     ddl m} ddl m} | |j                  t        j                  |j                  fv xr6 ||j
                  t        j
                  |j
                  fv xr | xr |xr |S Nr   )activations)ops	keras.srcr   r   tanhr   sigmoid)r   r   r   r   r   r   r   s          r   _do_gru_arguments_support_cudnnr     ss     & 	{''#((;; 	 S[[9:	 J	 		
 r   c                     ddl m} ddl m} | |j                  t        j                  |j                  fv xr2 ||j
                  t        j
                  |j
                  fv xr | xr |S r   r   )r   r   r   r   r   r   s         r    _do_lstm_arguments_support_cudnnr     si     & 	{''#((;; 	 S[[9:	 J	 r   c           
          t        j                  t        j                  t        j                  t        j                  | d            d            S )aX  Check if input sequence contains any fully masked data.

    cuDNN kernel will error out if the input sequence contains any fully masked
    data. We work around this issue by rerouting the computation to the
    standard kernel until the issue on the cuDNN side has been fixed. For a
    fully masked sequence, it will contain all `False` values. To make it easy
    to check, we invert the boolean and check if any of the sequences has all
    `True` values.

    Args:
        mask: The mask tensor.

    Returns:
        A boolean tensor, `True` if the mask contains a fully masked sequence.
    r   rA   r   r   )r   
reduce_any
reduce_alllogical_notr   )r   s    r   _has_fully_masked_sequencer     s7      ==
bnnRWWT%@AJ r   c                     t        j                  t        j                  t        |             t	        |             }t        j
                  |dg       y )Na  You are passing a RNN mask that does not correspond to right-padded sequences, while using cuDNN, which is not supported. With cuDNN, RNN masks can only be used for right-padding, e.g. `[[True, True, False, False]]` would be a valid mask, but any mask that isn't just contiguous `True`'s on the left and contiguous `False`'s on the right would be invalid. You can pass `use_cudnn=False` to your RNN layer to stop using cuDNN (this may be slower).)r   logical_andr   r   _is_sequence_right_paddedAssert)r   valids     r   _assert_valid_maskr   2  sF    NN
1$78!$'E IIF	
r   c                     fd}| D cg c]  }t        j                   ||      |        } }|D cg c]  }t        j                  ||       }}t        j                  | |z   d      S c c}w c c}w )a  Utility function convert variable to cuDNN compatible parameter.

    Note that Keras weights for kernels are different from the cuDNN format.
    Eg.:

    ```
      Keras                 cuDNN
      [[0, 1, 2],  <--->  [[0, 2, 4],
       [3, 4, 5]]          [1, 3, 5]]
    ```

    If the input weights need to be in a unified format, then set
    `transpose_weights=True` to convert the weights.

    Args:
        weights: list of weights for the kernels and recurrent kernels.
        biases: list of biases for individual gate.
        shape: the shape for the converted variables that will be feed to cuDNN.
        transpose_weights: boolean, whether to transpose the weights.

    Returns:
        The converted weights that can be feed to cuDNN ops as param.
    c                 6    rt        j                  |       S | S r%   )r   r   )wtranspose_weightss    r   convertz+_standardize_cudnn_weights.<locals>.converta  s    "3r||A::r   r   r   )r   reshapeconcat)weightsbiasesr   r   r   xs      `  r   _standardize_cudnn_weightsr   H  sh    2; 7>>rzz'!*e,>G>,23qbjjE"3F399Wv%A.. ?3s
   #A-A2c           	      x   t        j                  |       d   }t        j                  t        j                  | t         j                        d      }t        j
                  ||      }t        j                  t        j                  t        j                  | d      t        j                  |d                  S )aJ  Check the mask tensor and see if it right padded.

    cuDNN uses the sequence length param to skip the tailing
    timestep. If the data is left padded, or not a strict right padding (has
    masked value in the middle of the sequence), then cuDNN won't work
    properly in those cases.

    Left padded data: [[False, False, True, True, True]].
    Right padded data: [[True, True, True, False, False]].
    Mixture of mask/unmasked data: [[True, False, True, False, False]].

    Note that for the mixed data example above, the actually data RNN should see
    are those 2 Trues (index 0 and 2), the index 1 False should be ignored and
    not pollute the internal states.

    Args:
        mask: the Boolean tensor with shape [batch, timestep]

    Returns:
        boolean scalar tensor, whether the mask is strictly right padded.
    r   r   )maxlenr   r   )r   r   
reduce_sumr   rO   sequence_maskr   equal)r   max_seq_lengthcount_of_trueright_padded_masks       r   r   r   i  s    , XXd^A&NMM"''$"9BM((~N==
GGD'GG%V4	
 r   c                     |rdnd}t        j                  t        j                  | t         j                        |      S )a^  Calculate the sequence length tensor (1-D) based on the masking tensor.

    The masking tensor is a 2D boolean tensor with shape [batch, timestep]. For
    any timestep that should be masked, the corresponding field will be False.
    Consider the following example:
      a = [[True, True, False, False],
           [True, True, True, False]]
    It is a (2, 4) tensor, and the corresponding sequence length result should
    be 1D tensor with value [2, 3]. Note that the masking tensor must be right
    padded that could be checked by, e.g., `is_sequence_right_padded()`.

    Args:
        mask: Boolean tensor with shape [batch, timestep] or [timestep, batch]
            if time_major=True.
        time_major: Boolean, which indicates whether the mask is time major or
            batch major.

    Returns:
        sequence_length: 1D int32 tensor.
    r   r   r   )r   r   r   rO   )r   r   timestep_indexs      r   "_compute_sequence_length_from_maskr    s-    * %Q!N==rxx0~FFr   c                  R    t        t        j                  j                  d            S )NGPU)r   r   configlist_logical_devicesr3   r   r   _is_gpu_availabler    s    		..u566r   c	           
      2   |t        |       t        ||      }	nz|r1t        j                  |       d   }
t        j                  |       d   }n0t        j                  |       d   }
t        j                  |       d   }t        j                  |
g|      }	|s|	t        j
                  | d      } d\  }}n	|rdnd\  }}t        j                  ||      }t        j                  |dd      }|t        j                  |dd      z  }t        j                  t        j                  |d	g      d
      }t        j                  j                         d   rD|d   |d   c|d<   |d<   |d   |d   c|d<   |d<   |d   |d   c|d<   |d<   |d   |d   c|d<   |d<   t        ||t        j                  d	g      d      }|rt        j                  | |	||      } t        j                  j                  | |d|dd|	|      \  }}}}}|r1t        j                  ||	||      }t        j                   ||g      }|d	   }|s|	|rt        j
                  |g d      }t        j"                  ||      }|	|}|st        j                  ||rdnd      }|||gfS )z>GRU with cuDNN implementation which is only available for GPU.r   r   r   r   r   permr   r   r   r   r   r      is_cuda_build   Tr   r   r   r   seq_axis
batch_axisr   inputinput_hinput_cparamsis_trainingrnn_modesequence_lengthsr   )r   r  r   r   fillr   r   splitr   	sysconfigget_build_infor   r   reverse_sequenceraw_ops
CudnnRNNV3r'   squeeze)r/   r   r   r   r   r   r   r(   r   r  	batch_dimmax_sequence_lengthr  r  init_hr   r  r   hr!   r   states                         r   r   r     s    4 =dJO(+I"$((6"21"5(+I"$((6"21"577I;0CD*2f95%*)3v* ^^M9Fhhvqq)Grxx(!!44G 88BJJtbT*A.D	||""$_5 ")WQZ
GAJ!(WQZ
GAJ7DGQa7DGQa'kk2$	F  $$!	
 **//) 0 	GQ1a %%!	
 **WH:6"+K*27G,,wY7JJqx(E # ..
1J 		 r   c                 b    |t        | |||      }nt        | ||||      }|xr
 t               S )N)r   r   r   r   )r   r   r   r   r   )r   r   r  )r   r   r   r   r   args_supporteds         r   r   r     sL     9!!5	
 9!!5#
 1/11r   c                    t        ||||d u      }|st        ddlm} t	        ||      r|j
                  }t	        ||      r|j
                  }t	        ||      r|j
                  }	 t        | ||||||||
|	
      S # t        j                  j                  $ r t        t        j                  j                  $ r t        w xY w)N)r   r   r   )r   r   r   r   r   r   _cudnn_lstmr   r   r   r   )r/   initial_state_hinitial_state_cr   r   r   r   r   r   r   r(   r   r   r   r   s                  r   lstmr/  4  s     (&4t;KO !!5&(#"H-+11$!zz"
 	
 99)) "!!99"" "!!"s   )A= =ACc
           
         |t        |       t        ||      }
nz|r1t        j                  |       d   }t        j                  |       d   }n0t        j                  |       d   }t        j                  |       d   }t        j                  |g|      }
|s|
t        j
                  | d      } d\  }}n	|rdnd\  }}t        j                  ||      }t        j                  ||      }t        j                  |dd      }|t        j                  |dd      z  }t        j                  t        j                  |      |fd      }t        j                  j                         d	   r<d
D cg c]  }||   	 }}t        j                  |dd      }d
D cg c]  }||   	 }}t        |t        j                  |d      t        j                  dg      d      }|rt        j                  | |
||      } t        j                  j!                  | |||dd|
|      \  }}}}}|r1t        j                  ||
||      }t        j"                  ||g      }|d   }|s|
|	rt        j
                  |g d      }t        j$                  ||      }t        j$                  ||      }|
|}|	st        j                  ||rdnd      }||||gfS c c}w c c}w )Nr   r   r	  r
  r  r   r   r  is_rocm_build)r   r   r   r   r        r     r   Tr  r  r/  r  )r   r  r   r   r  r   r   r  r   rs   r  r  r   r   r   r!  r"  r'   r#  )r/   r-  r.  r   r   r   r   r   r(   r   r  r$  r%  r  r  r&  init_cr   	full_biasr   r  r   r'  cr!   r   s                             r   r,  r,  g  s    4 =dJO(+I"$((6"21"5(+I"$((6"21"577I;0CD*2f95%*)3v* ^^O(;F^^O(;Fhhvqq)Grxx(!!44G 		2==.5q9I	||""$_5 (@@!71:@@HHY2	+CDaYq\D	D'xx	1%kk2$	F  $$!	
 **//) 0 	GQ1a %%!	
 **WH:6"+K*27G,,wY7


18$A


18$A # ..
1J1a&))} A Es   0KKc                      t         r%   r   argskwargss     r   bidirectional_lstmr=        
r   c                      t         r%   r9  r:  s     r   bidirectional_grur@    r>  r   )FNNFNFFT)FFFFT)Fr%   )FFFF)
tensorflowr   r   r   r   r   r   r   r   r   r   r   r  r  r   r   r/  r,  r=  r@  r3   r   r   <module>rB     s      	x,H 3"l($*,/BBG27qr 2F 0"fn*br   