move ArraysMatch function into src/tim/vx/test_utils.h
Signed-off-by: Chen Xin <jack.chen@verisilicon.com>
This commit is contained in:
parent
3d64cfc4ef
commit
eb28f8b3ed
|
|
@ -28,19 +28,6 @@
|
|||
#include "gtest/gtest.h"
|
||||
#include "src/tim/vx/test_utils.h"
|
||||
|
||||
namespace {
|
||||
template<typename T>
|
||||
::testing::AssertionResult ArraysMatch(const std::vector<T>& expected,
|
||||
const std::vector<T>& actual,
|
||||
T abs_error){
|
||||
for (size_t i = 0; i < expected.size(); ++i){
|
||||
EXPECT_NEAR(expected[i], actual[i], abs_error) << "at index:" << i;
|
||||
}
|
||||
|
||||
return ::testing::AssertionSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Linear, shape_5_1_fp32) {
|
||||
auto ctx = tim::vx::Context::Create();
|
||||
auto graph = ctx->CreateGraph();
|
||||
|
|
@ -218,5 +205,5 @@ TEST(Gelu, shape_5_1_uint8_Quantized) {
|
|||
std::vector<uint8_t> output(golden.size());
|
||||
|
||||
EXPECT_TRUE(output_tensor->CopyDataFromTensor(output.data()));
|
||||
EXPECT_EQ(golden, output);
|
||||
EXPECT_TRUE(ArraysMatch(golden, output, (uint8_t)1));
|
||||
}
|
||||
|
|
@ -164,5 +164,5 @@ TEST(AddN, shape_2_2_uint8_Quantized) {
|
|||
std::vector<uint8_t> output(4);
|
||||
|
||||
EXPECT_TRUE(output_tensor->CopyDataFromTensor(output.data()));
|
||||
EXPECT_EQ(golden, output);
|
||||
EXPECT_TRUE(ArraysMatch(golden, output, (uint8_t)1));
|
||||
}
|
||||
|
|
@ -28,19 +28,6 @@
|
|||
#include "gtest/gtest.h"
|
||||
#include "src/tim/vx/test_utils.h"
|
||||
|
||||
namespace {
|
||||
template<typename T>
|
||||
::testing::AssertionResult ArraysMatch(const std::vector<T>& expected,
|
||||
const std::vector<T>& actual,
|
||||
T abs_error){
|
||||
for (size_t i = 0; i < expected.size(); ++i){
|
||||
EXPECT_NEAR(expected[i], actual[i], abs_error) << "at index:" << i;
|
||||
}
|
||||
|
||||
return ::testing::AssertionSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
TEST(AVG, shape_3_3_1_2_fp32_kernel_2_stride_1) {
|
||||
auto ctx = tim::vx::Context::Create();
|
||||
auto graph = ctx->CreateGraph();
|
||||
|
|
@ -183,7 +170,7 @@ TEST(AVG, shape_3_3_1_1_uint8_kernel_2_stride_1) {
|
|||
|
||||
std::vector<uint8_t> output(golden.size());
|
||||
EXPECT_TRUE(output_tensor->CopyDataFromTensor(output.data()));
|
||||
EXPECT_EQ(golden, output);
|
||||
EXPECT_TRUE(ArraysMatch(golden, output, (uint8_t)1));
|
||||
}
|
||||
|
||||
TEST(AVG, shape_60_52_3_5_fp32_kernel_35_stride_5) {
|
||||
|
|
@ -398,5 +385,5 @@ TEST(AVG_ANDROID, shape_60_52_3_5_uint8_kernel_35_stride_5) {
|
|||
|
||||
std::vector<uint8_t> output(golden.size());
|
||||
EXPECT_TRUE(output_tensor->CopyDataFromTensor(output.data()));
|
||||
EXPECT_EQ(golden, output);
|
||||
EXPECT_TRUE(ArraysMatch(golden, output, (uint8_t)1));
|
||||
}
|
||||
|
|
@ -24,22 +24,9 @@
|
|||
#include "tim/vx/context.h"
|
||||
#include "tim/vx/graph.h"
|
||||
#include "tim/vx/ops/conv1d.h"
|
||||
|
||||
#include "src/tim/vx/test_utils.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace {
|
||||
template<typename T>
|
||||
::testing::AssertionResult ArraysMatch(const std::vector<T>& expected,
|
||||
const std::vector<T>& actual,
|
||||
T abs_error){
|
||||
for (size_t i = 0; i < expected.size(); ++i){
|
||||
EXPECT_NEAR(expected[i], actual[i], abs_error) << "at index:" << i;
|
||||
}
|
||||
|
||||
return ::testing::AssertionSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Conv1d, shape_3_6_1_float_ksize_1_stride_1_weights_3_no_bias_whcn) {
|
||||
auto ctx = tim::vx::Context::Create();
|
||||
auto graph = ctx->CreateGraph();
|
||||
|
|
|
|||
|
|
@ -24,22 +24,9 @@
|
|||
#include "tim/vx/context.h"
|
||||
#include "tim/vx/graph.h"
|
||||
#include "tim/vx/ops/groupedconv2d.h"
|
||||
|
||||
#include "src/tim/vx/test_utils.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace {
|
||||
template<typename T>
|
||||
::testing::AssertionResult ArraysMatch(const std::vector<T>& expected,
|
||||
const std::vector<T>& actual,
|
||||
T abs_error){
|
||||
for (size_t i = 0; i < expected.size(); ++i){
|
||||
EXPECT_NEAR(expected[i], actual[i], abs_error) << "at index:" << i;
|
||||
}
|
||||
|
||||
return ::testing::AssertionSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
TEST(GroupedConv2d, shape_3_3_6_1_float_group_1_no_bias_whcn) {
|
||||
auto ctx = tim::vx::Context::Create();
|
||||
auto graph = ctx->CreateGraph();
|
||||
|
|
|
|||
|
|
@ -24,22 +24,9 @@
|
|||
#include "tim/vx/context.h"
|
||||
#include "tim/vx/graph.h"
|
||||
#include "tim/vx/ops/instancenormalization.h"
|
||||
|
||||
#include "src/tim/vx/test_utils.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace {
|
||||
template<typename T>
|
||||
::testing::AssertionResult ArraysMatch(const std::vector<T>& expected,
|
||||
const std::vector<T>& actual,
|
||||
T abs_error){
|
||||
for (size_t i = 0; i < expected.size(); ++i){
|
||||
EXPECT_NEAR(expected[i], actual[i], abs_error) << "at index:" << i;
|
||||
}
|
||||
|
||||
return ::testing::AssertionSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
TEST(InstanceNorm, shape_3_6_1_float) {
|
||||
auto ctx = tim::vx::Context::Create();
|
||||
auto graph = ctx->CreateGraph();
|
||||
|
|
|
|||
|
|
@ -24,22 +24,9 @@
|
|||
#include "tim/vx/context.h"
|
||||
#include "tim/vx/graph.h"
|
||||
#include "tim/vx/ops/layernormalization.h"
|
||||
|
||||
#include "src/tim/vx/test_utils.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace {
|
||||
template<typename T>
|
||||
::testing::AssertionResult ArraysMatch(const std::vector<T>& expected,
|
||||
const std::vector<T>& actual,
|
||||
T abs_error){
|
||||
for (size_t i = 0; i < expected.size(); ++i){
|
||||
EXPECT_NEAR(expected[i], actual[i], abs_error) << "at index:" << i;
|
||||
}
|
||||
|
||||
return ::testing::AssertionSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
TEST(LayerNorm, axis_0_shape_3_6_1_float) {
|
||||
auto ctx = tim::vx::Context::Create();
|
||||
auto graph = ctx->CreateGraph();
|
||||
|
|
|
|||
|
|
@ -24,22 +24,9 @@
|
|||
#include "tim/vx/context.h"
|
||||
#include "tim/vx/graph.h"
|
||||
#include "tim/vx/ops/logsoftmax.h"
|
||||
|
||||
#include "src/tim/vx/test_utils.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace {
|
||||
template<typename T>
|
||||
::testing::AssertionResult ArraysMatch(const std::vector<T>& expected,
|
||||
const std::vector<T>& actual,
|
||||
T abs_error){
|
||||
for (size_t i = 0; i < expected.size(); ++i){
|
||||
EXPECT_NEAR(expected[i], actual[i], abs_error) << "at index:" << i;
|
||||
}
|
||||
|
||||
return ::testing::AssertionSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
TEST(LogSoftmax, shape_6_1_float_axis_0) {
|
||||
auto ctx = tim::vx::Context::Create();
|
||||
auto graph = ctx->CreateGraph();
|
||||
|
|
|
|||
|
|
@ -24,22 +24,9 @@
|
|||
#include "tim/vx/context.h"
|
||||
#include "tim/vx/graph.h"
|
||||
#include "tim/vx/ops/matmul.h"
|
||||
|
||||
#include "src/tim/vx/test_utils.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace {
|
||||
template<typename T>
|
||||
::testing::AssertionResult ArraysMatch(const std::vector<T>& expected,
|
||||
const std::vector<T>& actual,
|
||||
T abs_error){
|
||||
for (size_t i = 0; i < expected.size(); ++i){
|
||||
EXPECT_NEAR(expected[i], actual[i], abs_error) << "at index:" << i;
|
||||
}
|
||||
|
||||
return ::testing::AssertionSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Matmul, shape_2_6_shape_6_2_float) {
|
||||
auto ctx = tim::vx::Context::Create();
|
||||
auto graph = ctx->CreateGraph();
|
||||
|
|
|
|||
|
|
@ -25,23 +25,9 @@
|
|||
#include "tim/vx/context.h"
|
||||
#include "tim/vx/graph.h"
|
||||
#include "tim/vx/ops/moments.h"
|
||||
|
||||
#include "src/tim/vx/test_utils.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace {
|
||||
template<typename T>
|
||||
::testing::AssertionResult ArraysMatch(const std::vector<T>& expected,
|
||||
const std::vector<T>& actual,
|
||||
T abs_error,
|
||||
const std::string& msg){
|
||||
for (size_t i = 0; i < expected.size(); ++i){
|
||||
EXPECT_NEAR(expected[i], actual[i], abs_error) << msg << " at index:" << i;
|
||||
}
|
||||
|
||||
return ::testing::AssertionSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Moments, shape_6_3_1_float_axes_0_1) {
|
||||
auto ctx = tim::vx::Context::Create();
|
||||
auto graph = ctx->CreateGraph();
|
||||
|
|
@ -113,7 +99,7 @@ TEST(Moments, shape_3_6_1_float_axes_1_keepdims) {
|
|||
-4, 0, 4,
|
||||
-5, 0, 5,
|
||||
-6, 0, 6,
|
||||
-7, 0, 7
|
||||
-7, 0, 7
|
||||
};
|
||||
|
||||
std::vector<float> mean_golden = {
|
||||
|
|
|
|||
|
|
@ -24,22 +24,9 @@
|
|||
#include "tim/vx/context.h"
|
||||
#include "tim/vx/graph.h"
|
||||
#include "tim/vx/ops/resize1d.h"
|
||||
|
||||
#include "src/tim/vx/test_utils.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace {
|
||||
template<typename T>
|
||||
::testing::AssertionResult ArraysMatch(const std::vector<T>& expected,
|
||||
const std::vector<T>& actual,
|
||||
T abs_error){
|
||||
for (size_t i = 0; i < expected.size(); ++i){
|
||||
EXPECT_NEAR(expected[i], actual[i], abs_error) << "at index:" << i;
|
||||
}
|
||||
|
||||
return ::testing::AssertionSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Resize1d, shape_4_2_1_float_nearest_whcn) {
|
||||
auto ctx = tim::vx::Context::Create();
|
||||
auto graph = ctx->CreateGraph();
|
||||
|
|
|
|||
|
|
@ -109,5 +109,30 @@ inline std::vector<float> Dequantize(const std::vector<T>& data, float scale,
|
|||
return f;
|
||||
}
|
||||
|
||||
namespace {
|
||||
template<typename T>
|
||||
::testing::AssertionResult ArraysMatch(const std::vector<T>& expected,
|
||||
const std::vector<T>& actual,
|
||||
T abs_error){
|
||||
for (size_t i = 0; i < expected.size(); ++i){
|
||||
EXPECT_NEAR(expected[i], actual[i], abs_error) << "at index:" << i;
|
||||
}
|
||||
|
||||
return ::testing::AssertionSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
template<typename T>
|
||||
::testing::AssertionResult ArraysMatch(const std::vector<T>& expected,
|
||||
const std::vector<T>& actual,
|
||||
T abs_error,
|
||||
const std::string& msg){
|
||||
for (size_t i = 0; i < expected.size(); ++i){
|
||||
EXPECT_NEAR(expected[i], actual[i], abs_error) << msg << " at index:" << i;
|
||||
}
|
||||
|
||||
return ::testing::AssertionSuccess();
|
||||
}
|
||||
}
|
||||
#endif /* TIM_VX_TEST_UTILS_H_ */
|
||||
Loading…
Reference in New Issue