Skip to content
Permalink
Browse files

Merge pull request #26640 from joyalbin:add_dynamic_pad_test

PiperOrigin-RevId: 238723763
  • Loading branch information...
tensorflower-gardener committed Mar 15, 2019
2 parents 7ea3243 + 6210c99 commit fed677e9dde08d13250e16ae935964aa390dc80d
@@ -1369,9 +1369,10 @@ cc_test(
size = "small",
srcs = ["subgraph_test_util_test.cc"],
deps = [
":kernel_util",
":subgraph_test_util",
":test_util",
"//tensorflow/lite:framework",
"//tensorflow/lite/kernels:test_util",
"@com_google_googletest//:gtest",
],
)
@@ -27,9 +27,11 @@ namespace tflite {
namespace ops {
namespace builtin {
// ADD and MUL are used to test simple branch.
// ADD and MUL can be used to test dynamic sized subgraphs with the
// use of IF op.
TfLiteRegistration* Register_ADD();
TfLiteRegistration* Register_MUL();
// ADD and MUL are used to test dynamic sized subgraphs.
// PAD is used to test dynamic sized subgraphs.
TfLiteRegistration* Register_PAD();
TfLiteRegistration* Register_LESS_EQUAL();
} // namespace builtin
@@ -16,6 +16,7 @@ limitations under the License.
#include "tensorflow/lite/kernels/subgraph_test_util.h"
#include <gtest/gtest.h>
#include "tensorflow/lite/interpreter.h"
#include "tensorflow/lite/kernels/kernel_util.h"
#include "tensorflow/lite/kernels/test_util.h"

namespace tflite {
@@ -106,6 +107,22 @@ TEST_F(SubgraphBuilderTest, TestBuildPadSubgraph) {
CheckIntTensor(output, {5}, {0, 5, 7, 0, 0});
}

TEST_F(SubgraphBuilderTest, TestBuildDynamicPadSubgraph) {
builder_->BuildPadSubgraph(&interpreter_->primary_subgraph());

interpreter_->ResizeInputTensor(interpreter_->inputs()[0], {2});
interpreter_->ResizeInputTensor(interpreter_->inputs()[1], {1, 2});
ASSERT_EQ(interpreter_->AllocateTensors(), kTfLiteOk);

FillIntTensor(interpreter_->tensor(interpreter_->inputs()[0]), {5, 7});
FillIntTensor(interpreter_->tensor(interpreter_->inputs()[1]), {1, 2});
ASSERT_EQ(interpreter_->Invoke(), kTfLiteOk);

TfLiteTensor* output = interpreter_->tensor(interpreter_->outputs()[0]);
EXPECT_TRUE(IsDynamicTensor(output));
CheckIntTensor(output, {5}, {0, 5, 7, 0, 0});
}

TEST_F(SubgraphBuilderTest, TestBuildLessEqualCondSubgraph) {
builder_->BuildLessEqualCondSubgraph(&interpreter_->primary_subgraph(), 3);

0 comments on commit fed677e

Please sign in to comment.
You can’t perform that action at this time.