Merge pull request #46962 from advaitjain:fix-exp-test-xtensa
PiperOrigin-RevId: 355944394 Change-Id: I52b83d393ea4e3b55cf73a8d0c73bd855a73090a
This commit is contained in:
commit
7dbb6cf44a
tensorflow/lite/micro
@ -235,6 +235,19 @@ tflite_micro_cc_test(
|
||||
],
|
||||
)
|
||||
|
||||
tflite_micro_cc_test(
|
||||
name = "exp_test",
|
||||
srcs = ["exp_test.cc"],
|
||||
deps = [
|
||||
":kernel_runner",
|
||||
"//tensorflow/lite/c:common",
|
||||
"//tensorflow/lite/micro:debug_log",
|
||||
"//tensorflow/lite/micro:op_resolvers",
|
||||
"//tensorflow/lite/micro:test_helpers",
|
||||
"//tensorflow/lite/micro/testing:micro_test",
|
||||
],
|
||||
)
|
||||
|
||||
tflite_micro_cc_test(
|
||||
name = "pooling_test",
|
||||
srcs = [
|
||||
|
@ -54,7 +54,6 @@ void TestExp(const int* input_dims_data, const float* input_data,
|
||||
TF_LITE_MICRO_EXPECT_NEAR(expected_output_data[i], output_data[i], 1e-5f);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace testing
|
||||
} // namespace tflite
|
||||
@ -62,13 +61,16 @@ void TestExp(const int* input_dims_data, const float* input_data,
|
||||
TF_LITE_MICRO_TESTS_BEGIN
|
||||
|
||||
TF_LITE_MICRO_TEST(SingleDim) {
|
||||
float output_data[7];
|
||||
const int input_dims[] = {2, 1, 7};
|
||||
const float input_values[] = {0.0f, 1.0f, -1.0f, 100.0f,
|
||||
-100.0f, 0.01f, -0.01f};
|
||||
const float golden[] = {
|
||||
1.0f, 2.71828f, 0.36788f, std::numeric_limits<float>::infinity(),
|
||||
1.17549e-38f, 1.01005f, 0.99005f};
|
||||
constexpr int kInputSize = 7;
|
||||
float output_data[kInputSize];
|
||||
const int input_dims[] = {2, 1, kInputSize};
|
||||
const float input_values[kInputSize] = {0.0f, 1.0f, -1.0f, 100.0f,
|
||||
-100.0f, 0.01f, -0.01f};
|
||||
float golden[kInputSize];
|
||||
for (int i = 0; i < kInputSize; ++i) {
|
||||
golden[i] = std::exp(input_values[i]);
|
||||
}
|
||||
|
||||
tflite::testing::TestExp(input_dims, input_values, golden, output_data);
|
||||
}
|
||||
|
||||
|
@ -142,12 +142,14 @@ extern bool did_test_fail;
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
// The check vx != vy is needed to properly handle the case where both
|
||||
// x and y evaluate to infinity. See #46960 for more details.
|
||||
#define TF_LITE_MICRO_EXPECT_NEAR(x, y, epsilon) \
|
||||
do { \
|
||||
auto vx = (x); \
|
||||
auto vy = (y); \
|
||||
auto delta = ((vx) > (vy)) ? ((vx) - (vy)) : ((vy) - (vx)); \
|
||||
if (delta > epsilon) { \
|
||||
if (vx != vy && delta > epsilon) { \
|
||||
MicroPrintf(#x " (%f) near " #y " (%f) failed at %s:%d", \
|
||||
static_cast<double>(vx), static_cast<double>(vy), __FILE__, \
|
||||
__LINE__); \
|
||||
|
Loading…
Reference in New Issue
Block a user