From 274fa1db82bd5fc3c983cc7081a9dd80979f2013 Mon Sep 17 00:00:00 2001 From: Yu-Cheng Ling Date: Tue, 10 Jul 2018 15:21:32 -0700 Subject: Reset variable tensors to zero after allocating tensors. PiperOrigin-RevId: 204022562 --- tensorflow/contrib/lite/interpreter_test.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tensorflow/contrib/lite/interpreter_test.cc') diff --git a/tensorflow/contrib/lite/interpreter_test.cc b/tensorflow/contrib/lite/interpreter_test.cc index 4fa97512fc..10119903fe 100644 --- a/tensorflow/contrib/lite/interpreter_test.cc +++ b/tensorflow/contrib/lite/interpreter_test.cc @@ -57,6 +57,22 @@ TEST(BasicInterpreter, InvokeInvalidModel) { ASSERT_EQ(interpreter.Invoke(), kTfLiteOk); } +TEST(BasicInterpreter, TestAllocateTensorsResetVariableTensors) { + Interpreter interpreter; + int tensor_index; + ASSERT_EQ(interpreter.AddTensors(1, &tensor_index), kTfLiteOk); + constexpr int kTensorSize = 16; + interpreter.SetTensorParametersReadWrite(tensor_index, kTfLiteFloat32, "", + {kTensorSize}, {}, true); + interpreter.SetVariables({tensor_index}); + ASSERT_EQ(interpreter.AllocateTensors(), kTfLiteOk); + TfLiteTensor* tensor = interpreter.tensor(tensor_index); + // Ensure that variable tensors are reset to zero. + for (int i = 0; i < kTensorSize; ++i) { + ASSERT_EQ(tensor->data.f[i], 0.0f); + } +} + // Test size accessor functions. TEST(BasicInterpreter, TestSizeFunctions) { Interpreter interpreter; -- cgit v1.2.3