code: def test_masking(self):
      sequence = np.arange(24).reshape((2, 4, 3)).astype("float32")
      mask = np.array(
          [[True, True, False, True], [True, False, False, True]]
      )
      layer = layers.SimpleRNN(
          4,
          kernel_initializer=initializers.Constant(0.01),
          recurrent_initializer=initializers.Constant(0.02),
          bias_initializer=initializers.Constant(0.03),
          unroll=True,
      )
      output = layer(sequence, mask=mask)
      self.assertAllClose(
          np.array(
              [
                  [0.32951632, 0.32951632, 0.32951632, 0.32951632],
                  [0.61799484, 0.61799484, 0.61799484, 0.61799484],
              ]
          ),
          output,
      )
  
      layer = layers.SimpleRNN(
          2,
          kernel_initializer=initializers.Constant(0.01),
          recurrent_initializer=initializers.Constant(0.02),
          bias_initializer=initializers.Constant(0.03),
          return_sequences=True,
      )
      output = layer(sequence, mask=mask)
      self.assertAllClose(
          np.array(
              [
                  [0.0599281, 0.0599281],
                  [0.15122814, 0.15122814],
                  [0.15122814, 0.15122814],
                  [0.32394567, 0.32394567],
              ],
          ),
          output[0],
      )
      self.assertAllClose(
          np.array(
              [
                  [0.3969304, 0.3969304],
                  [0.3969304, 0.3969304],
                  [0.3969304, 0.3969304],
                  [0.608085, 0.608085],
              ],
          ),
          output[1],
      )
  
      layer = layers.SimpleRNN(
          2,
          kernel_initializer=initializers.Constant(0.01),
          recurrent_initializer=initializers.Constant(0.02),
          bias_initializer=initializers.Constant(0.03),
          return_sequences=True,
          zero_output_for_mask=True,
      )
      output = layer(sequence, mask=mask)
      self.assertAllClose(
          np.array(
              [
                  [0.0599281, 0.0599281],
                  [0.15122814, 0.15122814],
                  [0.0, 0.0],
                  [0.32394567, 0.32394567],
              ],
          ),
          output[0],
      )
      self.assertAllClose(
          np.array(
              [
                  [0.3969304, 0.3969304],
                  [0.0, 0.0],
                  [0.0, 0.0],
                  [0.608085, 0.608085],
              ],
          ),
          output[1],
      )
  
      layer = layers.SimpleRNN(
          4,
          kernel_initializer=initializers.Constant(0.01),
          recurrent_initializer=initializers.Constant(0.02),
          bias_initializer=initializers.Constant(0.03),
          go_backwards=True,
      )
      output = layer(sequence, mask=mask)
      self.assertAllClose(
          np.array(
              [
                  [0.07376196, 0.07376196, 0.07376196, 0.07376196],
                  [0.43645123, 0.43645123, 0.43645123, 0.43645123],
              ]
          ),
          output,
      )
  
file_path: keras/keras/layers/rnn/simple_rnn_test.py
imports: import numpy
  import pytest
  from keras import initializers
  from keras import layers
  from keras import testing
label_desc: Use image node_id 5 for calling the SimpleRNNTest obj's underlying member method code with example usage: obj.test_masking() without return types