Clarify tests and remove tests for unsupported types.
PiperOrigin-RevId: 265178265
This commit is contained in:
parent
dac733509f
commit
ff72e812c4
@ -24,7 +24,6 @@ namespace tflite {
|
|||||||
namespace testing {
|
namespace testing {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// If expected output is empty, the test is expected to fail.
|
|
||||||
void TestArgMinMax(TfLiteTensor* input_tensor, TfLiteTensor* axis_tensor,
|
void TestArgMinMax(TfLiteTensor* input_tensor, TfLiteTensor* axis_tensor,
|
||||||
TfLiteTensor* output_tensor,
|
TfLiteTensor* output_tensor,
|
||||||
std::initializer_list<int> expected_output_data,
|
std::initializer_list<int> expected_output_data,
|
||||||
@ -72,13 +71,6 @@ void TestArgMinMax(TfLiteTensor* input_tensor, TfLiteTensor* axis_tensor,
|
|||||||
TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, registration->prepare(&context, &node));
|
TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, registration->prepare(&context, &node));
|
||||||
}
|
}
|
||||||
TF_LITE_MICRO_EXPECT_NE(nullptr, registration->invoke);
|
TF_LITE_MICRO_EXPECT_NE(nullptr, registration->invoke);
|
||||||
// TODO(139763483): this is misleading. We should be more explicit about
|
|
||||||
// expecting failure conditions.
|
|
||||||
if (!expected_output_data.size()) {
|
|
||||||
TF_LITE_MICRO_EXPECT_EQ(kTfLiteError,
|
|
||||||
registration->invoke(&context, &node));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, registration->invoke(&context, &node));
|
TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, registration->invoke(&context, &node));
|
||||||
if (registration->free) {
|
if (registration->free) {
|
||||||
registration->free(&context, user_data);
|
registration->free(&context, user_data);
|
||||||
@ -88,6 +80,7 @@ void TestArgMinMax(TfLiteTensor* input_tensor, TfLiteTensor* axis_tensor,
|
|||||||
output_tensor->data.i32[i], 1e-5f);
|
output_tensor->data.i32[i], 1e-5f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace testing
|
} // namespace testing
|
||||||
} // namespace tflite
|
} // namespace tflite
|
||||||
@ -149,26 +142,6 @@ TF_LITE_MICRO_TEST(GetMaxArgInt8) {
|
|||||||
{1});
|
{1});
|
||||||
}
|
}
|
||||||
|
|
||||||
TF_LITE_MICRO_TEST(GetMaxArgInt32) {
|
|
||||||
using tflite::testing::F2Q32;
|
|
||||||
int32_t output_data[1];
|
|
||||||
float input_scale = 7.436e-9;
|
|
||||||
TfLiteIntArray* input_dims =
|
|
||||||
tflite::testing::IntArrayFromInitializer({4, 1, 1, 1, 4});
|
|
||||||
auto input_data = {F2Q32(1, input_scale), F2Q32(9, input_scale),
|
|
||||||
F2Q32(7, input_scale), F2Q32(3, input_scale)};
|
|
||||||
auto input_tensor = tflite::testing::CreateQuantized32Tensor(
|
|
||||||
input_data, input_dims, "input_tensor", input_scale);
|
|
||||||
auto axis_tensor = tflite::testing::CreateTensor<int32_t, kTfLiteInt32>(
|
|
||||||
{3}, tflite::testing::IntArrayFromInitializer({3, 1, 1, 1}),
|
|
||||||
"axis_tensor");
|
|
||||||
auto output_tensor = tflite::testing::CreateTensor<int32_t, kTfLiteInt32>(
|
|
||||||
output_data, tflite::testing::IntArrayFromInitializer({3, 1, 1, 1}),
|
|
||||||
"output_tensor");
|
|
||||||
tflite::testing::TestArgMinMax(&input_tensor, &axis_tensor, &output_tensor,
|
|
||||||
{}); // Expects {1} if supported.
|
|
||||||
}
|
|
||||||
|
|
||||||
TF_LITE_MICRO_TEST(GetMaxArgMulDimensions) {
|
TF_LITE_MICRO_TEST(GetMaxArgMulDimensions) {
|
||||||
using tflite::testing::F2Q;
|
using tflite::testing::F2Q;
|
||||||
int32_t output_data[2];
|
int32_t output_data[2];
|
||||||
@ -217,54 +190,6 @@ TF_LITE_MICRO_TEST(GetMaxArgNegativeAxis) {
|
|||||||
{0, 1, 0, 0});
|
{0, 1, 0, 0});
|
||||||
}
|
}
|
||||||
|
|
||||||
TF_LITE_MICRO_TEST(GetMaxArgOutput64) {
|
|
||||||
using tflite::testing::F2Q;
|
|
||||||
int64_t output_data[2];
|
|
||||||
float input_min = 0;
|
|
||||||
float input_max = 15.9375;
|
|
||||||
TfLiteIntArray* input_dims =
|
|
||||||
tflite::testing::IntArrayFromInitializer({4, 1, 1, 2, 4});
|
|
||||||
auto input_data = {
|
|
||||||
F2Q(10, input_min, input_max), F2Q(2, input_min, input_max),
|
|
||||||
F2Q(7, input_min, input_max), F2Q(8, input_min, input_max),
|
|
||||||
F2Q(1, input_min, input_max), F2Q(9, input_min, input_max),
|
|
||||||
F2Q(7, input_min, input_max), F2Q(3, input_min, input_max)};
|
|
||||||
auto input_tensor = tflite::testing::CreateQuantizedTensor(
|
|
||||||
input_data, input_dims, "input_tensor", input_min, input_max);
|
|
||||||
auto axis_tensor = tflite::testing::CreateTensor<int32_t, kTfLiteInt32>(
|
|
||||||
{3}, tflite::testing::IntArrayFromInitializer({3, 1, 1, 1}),
|
|
||||||
"axis_tensor");
|
|
||||||
auto output_tensor = tflite::testing::CreateTensor<int64_t, kTfLiteInt64>(
|
|
||||||
output_data, tflite::testing::IntArrayFromInitializer({3, 1, 1, 2}),
|
|
||||||
"output_tensor");
|
|
||||||
tflite::testing::TestArgMinMax(&input_tensor, &axis_tensor, &output_tensor,
|
|
||||||
{}); // Expects {0, 1} if supported.
|
|
||||||
}
|
|
||||||
|
|
||||||
TF_LITE_MICRO_TEST(GetMaxArgAxis64) {
|
|
||||||
using tflite::testing::F2Q;
|
|
||||||
int32_t output_data[2];
|
|
||||||
float input_min = 0;
|
|
||||||
float input_max = 15.9375;
|
|
||||||
TfLiteIntArray* input_dims =
|
|
||||||
tflite::testing::IntArrayFromInitializer({4, 1, 1, 2, 4});
|
|
||||||
auto input_data = {
|
|
||||||
F2Q(10, input_min, input_max), F2Q(2, input_min, input_max),
|
|
||||||
F2Q(7, input_min, input_max), F2Q(8, input_min, input_max),
|
|
||||||
F2Q(1, input_min, input_max), F2Q(9, input_min, input_max),
|
|
||||||
F2Q(7, input_min, input_max), F2Q(3, input_min, input_max)};
|
|
||||||
auto input_tensor = tflite::testing::CreateQuantizedTensor(
|
|
||||||
input_data, input_dims, "input_tensor", input_min, input_max);
|
|
||||||
auto axis_tensor = tflite::testing::CreateTensor<int64_t, kTfLiteInt64>(
|
|
||||||
{3}, tflite::testing::IntArrayFromInitializer({3, 1, 1, 1}),
|
|
||||||
"axis_tensor");
|
|
||||||
auto output_tensor = tflite::testing::CreateTensor<int32_t, kTfLiteInt32>(
|
|
||||||
output_data, tflite::testing::IntArrayFromInitializer({3, 1, 1, 2}),
|
|
||||||
"output_tensor");
|
|
||||||
tflite::testing::TestArgMinMax(&input_tensor, &axis_tensor, &output_tensor,
|
|
||||||
{}); // Expects {0, 1} if supported.
|
|
||||||
}
|
|
||||||
|
|
||||||
TF_LITE_MICRO_TEST(GetMinArgFloat) {
|
TF_LITE_MICRO_TEST(GetMinArgFloat) {
|
||||||
int32_t output_data[1];
|
int32_t output_data[1];
|
||||||
TfLiteIntArray* input_dims =
|
TfLiteIntArray* input_dims =
|
||||||
@ -346,52 +271,4 @@ TF_LITE_MICRO_TEST(GetMinArgMulDimensions) {
|
|||||||
{0, 0}, true);
|
{0, 0}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
TF_LITE_MICRO_TEST(GetMinArgOutput64) {
|
|
||||||
using tflite::testing::F2Q;
|
|
||||||
float input_min = 0;
|
|
||||||
float input_max = 15.9375;
|
|
||||||
int64_t output_data[2];
|
|
||||||
TfLiteIntArray* input_dims =
|
|
||||||
tflite::testing::IntArrayFromInitializer({4, 1, 1, 2, 4});
|
|
||||||
auto input_data = {
|
|
||||||
F2Q(10, input_min, input_max), F2Q(2, input_min, input_max),
|
|
||||||
F2Q(7, input_min, input_max), F2Q(8, input_min, input_max),
|
|
||||||
F2Q(1, input_min, input_max), F2Q(9, input_min, input_max),
|
|
||||||
F2Q(7, input_min, input_max), F2Q(3, input_min, input_max)};
|
|
||||||
auto input_tensor = tflite::testing::CreateQuantizedTensor(
|
|
||||||
input_data, input_dims, "input_tensor", input_min, input_max);
|
|
||||||
auto axis_tensor = tflite::testing::CreateTensor<int32_t, kTfLiteInt32>(
|
|
||||||
{3}, tflite::testing::IntArrayFromInitializer({3, 1, 1, 1}),
|
|
||||||
"axis_tensor");
|
|
||||||
auto output_tensor = tflite::testing::CreateTensor<int64_t, kTfLiteInt64>(
|
|
||||||
output_data, tflite::testing::IntArrayFromInitializer({3, 1, 1, 2}),
|
|
||||||
"output_tensor");
|
|
||||||
tflite::testing::TestArgMinMax(&input_tensor, &axis_tensor, &output_tensor,
|
|
||||||
{}, true); // Expects {1, 0} if supported.
|
|
||||||
}
|
|
||||||
|
|
||||||
TF_LITE_MICRO_TEST(GetMinArgAxis64) {
|
|
||||||
using tflite::testing::F2Q;
|
|
||||||
float input_min = 0;
|
|
||||||
float input_max = 15.9375;
|
|
||||||
int32_t output_data[2];
|
|
||||||
TfLiteIntArray* input_dims =
|
|
||||||
tflite::testing::IntArrayFromInitializer({4, 1, 1, 2, 4});
|
|
||||||
auto input_data = {
|
|
||||||
F2Q(10, input_min, input_max), F2Q(2, input_min, input_max),
|
|
||||||
F2Q(7, input_min, input_max), F2Q(8, input_min, input_max),
|
|
||||||
F2Q(1, input_min, input_max), F2Q(9, input_min, input_max),
|
|
||||||
F2Q(7, input_min, input_max), F2Q(3, input_min, input_max)};
|
|
||||||
auto input_tensor = tflite::testing::CreateQuantizedTensor(
|
|
||||||
input_data, input_dims, "input_tensor", input_min, input_max);
|
|
||||||
auto axis_tensor = tflite::testing::CreateTensor<int64_t, kTfLiteInt64>(
|
|
||||||
{3}, tflite::testing::IntArrayFromInitializer({3, 1, 1, 1}),
|
|
||||||
"axis_tensor");
|
|
||||||
auto output_tensor = tflite::testing::CreateTensor<int32_t, kTfLiteInt32>(
|
|
||||||
output_data, tflite::testing::IntArrayFromInitializer({3, 1, 1, 2}),
|
|
||||||
"output_tensor");
|
|
||||||
tflite::testing::TestArgMinMax(&input_tensor, &axis_tensor, &output_tensor,
|
|
||||||
{}, true); // Expects {1, 0} if supported
|
|
||||||
}
|
|
||||||
|
|
||||||
TF_LITE_MICRO_TESTS_END
|
TF_LITE_MICRO_TESTS_END
|
||||||
|
@ -38,7 +38,8 @@ template <typename T>
|
|||||||
void TestReshapeImpl(TfLiteTensor* input_tensor, TfLiteTensor* shape_tensor,
|
void TestReshapeImpl(TfLiteTensor* input_tensor, TfLiteTensor* shape_tensor,
|
||||||
TfLiteTensor* output_tensor,
|
TfLiteTensor* output_tensor,
|
||||||
std::initializer_list<T> expected_output,
|
std::initializer_list<T> expected_output,
|
||||||
std::initializer_list<int> expected_dims) {
|
std::initializer_list<int> expected_dims,
|
||||||
|
bool expect_failure) {
|
||||||
TfLiteContext context;
|
TfLiteContext context;
|
||||||
TfLiteTensor tensors[3];
|
TfLiteTensor tensors[3];
|
||||||
TfLiteNode node;
|
TfLiteNode node;
|
||||||
@ -85,8 +86,7 @@ void TestReshapeImpl(TfLiteTensor* input_tensor, TfLiteTensor* shape_tensor,
|
|||||||
if (registration->prepare) {
|
if (registration->prepare) {
|
||||||
TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, registration->prepare(&context, &node));
|
TF_LITE_MICRO_EXPECT_EQ(kTfLiteOk, registration->prepare(&context, &node));
|
||||||
}
|
}
|
||||||
TF_LITE_MICRO_EXPECT_NE(nullptr, registration->invoke);
|
if (expect_failure) {
|
||||||
if (expected_output.size() == 0) {
|
|
||||||
TF_LITE_MICRO_EXPECT_EQ(kTfLiteError,
|
TF_LITE_MICRO_EXPECT_EQ(kTfLiteError,
|
||||||
registration->invoke(&context, &node));
|
registration->invoke(&context, &node));
|
||||||
return;
|
return;
|
||||||
@ -116,7 +116,8 @@ void TestReshape(std::initializer_list<int> input_dims_data,
|
|||||||
std::initializer_list<int32_t> shape_data,
|
std::initializer_list<int32_t> shape_data,
|
||||||
int* output_dims_data, uint8_t* output_data_raw,
|
int* output_dims_data, uint8_t* output_data_raw,
|
||||||
std::initializer_list<T> expected_output,
|
std::initializer_list<T> expected_output,
|
||||||
std::initializer_list<int> expected_dims) {
|
std::initializer_list<int> expected_dims,
|
||||||
|
bool expect_failure = false) {
|
||||||
TfLiteIntArray* input_dims = IntArrayFromInitializer(input_dims_data);
|
TfLiteIntArray* input_dims = IntArrayFromInitializer(input_dims_data);
|
||||||
TfLiteIntArray* output_dims = IntArrayFromInts(output_dims_data);
|
TfLiteIntArray* output_dims = IntArrayFromInts(output_dims_data);
|
||||||
TfLiteTensor input_tensor = CreateTensor<T, tensor_input_type>(
|
TfLiteTensor input_tensor = CreateTensor<T, tensor_input_type>(
|
||||||
@ -126,13 +127,13 @@ void TestReshape(std::initializer_list<int> input_dims_data,
|
|||||||
output_data, output_dims, "input_tensor");
|
output_data, output_dims, "input_tensor");
|
||||||
// Reshape param is passed as op's param.
|
// Reshape param is passed as op's param.
|
||||||
TestReshapeImpl<T>(&input_tensor, nullptr, &output_tensor, expected_output,
|
TestReshapeImpl<T>(&input_tensor, nullptr, &output_tensor, expected_output,
|
||||||
expected_dims);
|
expected_dims, expect_failure);
|
||||||
// Reshape param is passed as a tensor.
|
// Reshape param is passed as a tensor.
|
||||||
TfLiteIntArray* shape_dims = IntArrayFromInitializer(shape_dims_data);
|
TfLiteIntArray* shape_dims = IntArrayFromInitializer(shape_dims_data);
|
||||||
auto shape_tensor = CreateTensor<int32_t, kTfLiteInt32>(
|
auto shape_tensor = CreateTensor<int32_t, kTfLiteInt32>(
|
||||||
shape_data, shape_dims, "shape_tensor");
|
shape_data, shape_dims, "shape_tensor");
|
||||||
TestReshapeImpl<T>(&input_tensor, &shape_tensor, &output_tensor,
|
TestReshapeImpl<T>(&input_tensor, &shape_tensor, &output_tensor,
|
||||||
expected_output, expected_dims);
|
expected_output, expected_dims, expect_failure);
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace testing
|
} // namespace testing
|
||||||
@ -155,7 +156,8 @@ TF_LITE_MICRO_TEST(MismatchedDimensions) {
|
|||||||
{2, 1}, // shape_data
|
{2, 1}, // shape_data
|
||||||
output_dims, // output_dims
|
output_dims, // output_dims
|
||||||
output_data, {}, // expected_output
|
output_data, {}, // expected_output
|
||||||
{} // expected_dims
|
{}, // expected_dims
|
||||||
|
true // expect failure
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,7 +185,8 @@ TF_LITE_MICRO_TEST(TooManySpecialDimensions) {
|
|||||||
{-1, -1, 2, 4}, // shape_data
|
{-1, -1, 2, 4}, // shape_data
|
||||||
output_dims, // output_dims
|
output_dims, // output_dims
|
||||||
output_data, {}, // expected_output
|
output_data, {}, // expected_output
|
||||||
{} // expected_dims
|
{}, // expected_dims
|
||||||
|
true // expect failure
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,7 +208,8 @@ TF_LITE_MICRO_TEST(InvalidShape) {
|
|||||||
nullptr, // shape_tensor
|
nullptr, // shape_tensor
|
||||||
&output_tensor, // output_tensor
|
&output_tensor, // output_tensor
|
||||||
{}, // expected_output
|
{}, // expected_output
|
||||||
{} // expected_dims
|
{}, // expected_dims
|
||||||
|
true // expect failure
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,13 +275,15 @@ TF_LITE_MICRO_TEST(LegacyScalarOutput) {
|
|||||||
&shape_tensor, // shape_tensor
|
&shape_tensor, // shape_tensor
|
||||||
&output_tensor, // output_tensor
|
&output_tensor, // output_tensor
|
||||||
{}, // expected_output
|
{}, // expected_output
|
||||||
{} // expected_dims
|
{}, // expected_dims
|
||||||
|
true // expect failure
|
||||||
);
|
);
|
||||||
tflite::testing::TestReshapeImpl<float>(&input_tensor, // input_tensor
|
tflite::testing::TestReshapeImpl<float>(&input_tensor, // input_tensor
|
||||||
nullptr, // shape_tensor
|
nullptr, // shape_tensor
|
||||||
&output_tensor, // output_tensor
|
&output_tensor, // output_tensor
|
||||||
{3}, // expected_output
|
{3}, // expected_output
|
||||||
{} // expected_dims
|
{}, // expected_dims
|
||||||
|
false // expect failure
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user