Add new return_state test for RNNs
@@ -266,6 +266,7 @@ def test_specify_state_with_masking(layer_class):
targets = np.random.random((num_samples, units))
model.fit([inputs] + initial_state, targets)
+
@rnn_test
def test_return_state(layer_class):
num_states = 2 if layer_class is recurrent.LSTM else 1
@@ -281,5 +282,19 @@ def test_return_state(layer_class):
state = model.predict(inputs)
np.testing.assert_allclose(K.eval(layer.states[0]), state, atol=1e-4)
+
+@rnn_test
+def test_state_reuse(layer_class):
+ inputs = Input(batch_shape=(num_samples, timesteps, embedding_dim))
+ layer = layer_class(units, return_state=True, return_sequences=True)
+ outputs = layer(inputs)
+ output, state = outputs[0], outputs[1:]
+ output = layer_class(units)(output, initial_state=state)
+ model = Model(inputs, output)
+
+ inputs = np.random.random((num_samples, timesteps, embedding_dim))
+ outputs = model.predict(inputs)
+
+
if __name__ == '__main__':
pytest.main([__file__])
