o
    bi	                     @   s*   d dl mZ d dl mZ G dd dZdS )    )backend)opsc                   @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )DropoutRNNCella  Object that holds dropout-related functionality for RNN cells.

    This class is not a standalone RNN cell. It suppose to be used with a RNN
    cell by multiple inheritance. Any cell that mix with class should have
    following fields:

    - `dropout`: a float number in the range `[0, 1]`.
        Dropout rate for the input tensor.
    - `recurrent_dropout`: a float number in the range `[0, 1]`.
        Dropout rate for the recurrent connections.
    - `seed_generator`, an instance of `backend.random.SeedGenerator`.

    This object will create and cache dropout masks, and reuse them for
    all incoming steps, so that the same mask is used for every step.
    c                    sL   t dd }t||d u rtjj jdS  fddt|D S )Ndropout_mask_countrateseedc                    s    g | ]}t jj jd qS )r   )r   randomdropoutseed_generator).0_dropout_rateonesself Y/home/ubuntu/.local/lib/python3.10/site-packages/keras/src/layers/rnn/dropout_rnn_cell.py
<listcomp>   s    z7DropoutRNNCell._create_dropout_mask.<locals>.<listcomp>)getattrr   	ones_liker   r	   r
   r   range)r   
step_inputr   countr   r   r   _create_dropout_mask   s   
z#DropoutRNNCell._create_dropout_maskc                 C   :   t | dsd | _| jd u r| jdkr| || j| _| jS )N_dropout_maskr   )hasattrr   r
   r   r   r   r   r   r   get_dropout_mask%      
zDropoutRNNCell.get_dropout_maskc                 C   r   )N_recurrent_dropout_maskr   )r   r!   recurrent_dropoutr   r   r   r   r   get_recurrent_dropout_mask.   r    z)DropoutRNNCell.get_recurrent_dropout_maskc                 C   s
   d| _ dS )a/  Reset the cached dropout mask if any.

        The RNN layer invokes this in the `call()` method
        so that the cached mask is cleared after calling `cell.call()`. The
        mask should be cached across all timestep within the same batch, but
        shouldn't be cached between batches.
        N)r   r   r   r   r   reset_dropout_mask7   s   
z!DropoutRNNCell.reset_dropout_maskc                 C   s
   d | _ d S )N)r!   r$   r   r   r   reset_recurrent_dropout_maskA   s   
z+DropoutRNNCell.reset_recurrent_dropout_maskN)	__name__
__module____qualname____doc__r   r   r#   r%   r&   r   r   r   r   r      s    		
r   N)	keras.srcr   r   r   r   r   r   r   <module>   s    