From d6ec0033e6341b76c3d08300e3d22ed981237151 Mon Sep 17 00:00:00 2001 From: hejunchao Date: Wed, 23 Aug 2023 18:13:43 +0800 Subject: [PATCH] json --- tests/kernels/test_prelu.cpp | 57 ++++++++++++++++++++++++----------- tests/kernels/test_prelu.json | 5 +++ 2 files changed, 44 insertions(+), 18 deletions(-) create mode 100644 tests/kernels/test_prelu.json diff --git a/tests/kernels/test_prelu.cpp b/tests/kernels/test_prelu.cpp index 9c09fdda2a..b5d1df3ef4 100644 --- a/tests/kernels/test_prelu.cpp +++ b/tests/kernels/test_prelu.cpp @@ -22,17 +22,22 @@ #include #include +#define TEST_CASE_NAME "test_prelu" + using namespace nncase; using namespace nncase::runtime; using namespace ortki; using slope_t = itlib::small_vector; class PreluTest : public KernelTest, - public ::testing::TestWithParam< - std::tuple> { + public ::testing::TestWithParam> { public: void SetUp() override { - auto &&[typecode, l_shape, slope_value] = GetParam(); + READY_SUBCASE() + + auto l_shape = GetShapeArray("lhs_shape"); + auto typecode = GetDataType("lhs_type"); + auto slope_value = GetSlopeArray("slope"); input = hrt::create(typecode, l_shape, host_runtime_tensor::pool_cpu_only) @@ -49,26 +54,30 @@ class PreluTest : public KernelTest, void TearDown() override {} + slope_t GetSlopeArray(const char *key) { + assert(_document[key].IsArray()); + Value &array = _document[key]; + size_t arraySize = array.Size(); + slope_t cArray(arraySize); + for (rapidjson::SizeType i = 0; i < arraySize; i++) { + if (array[i].IsFloat()) { + cArray[i] = array[i].GetFloat(); + } else { + std::cout << "Invalid JSON format. Expected unsigned float " + "values in the array." + << std::endl; + } + } + return cArray; + } + protected: runtime_tensor input; slope_t slope; }; -INSTANTIATE_TEST_SUITE_P( - Prelu, PreluTest, - testing::Combine( - testing::Values(dt_float32), - testing::Values(dims_t{1, 3, 16, 16}, dims_t{1}, dims_t{8, 8}, - dims_t{1, 4, 16}, dims_t{1, 3, 24, 24}), - testing::Values( - slope_t{0.2f}, slope_t{0.1f}, slope_t{0.3f}, - slope_t{0.2f, 0.1f, 0.3f, 0.2f, 0.1f, 0.3f, 0.2f, 0.1f, - 0.3f, 0.2f, 0.1f, 0.3f, 0.2f, 0.1f, 0.3f, 0.2f, - 0.1f, 0.3f, 0.2f, 0.1f, 0.3f, 0.2f, 0.1f, 0.3f}, - slope_t{0.1f, 0.2f, 0.2f, 0.4f, 0.2f, 0.2f, 0.3f, 0.8f}, - slope_t{0.1f, 0.2f, 0.2f, 0.2f, 0.1f, 0.2f, 0.2f, 0.4f, 0.1f, 0.2f, - 0.2f, 0.8f, 0.2f, 0.12f, 0.2f, 0.21f}, - slope_t{0.1f, 0.2f, 0.3f, 0.1f, 0.2f, 0.3f, 0.1f, 0.2f}))); +INSTANTIATE_TEST_SUITE_P(Prelu, PreluTest, + testing::Combine(testing::Range(0, MAX_CASE_NUM))); TEST_P(PreluTest, Prelu) { auto l_ort = runtime_tensor_2_ort_tensor(input); @@ -113,6 +122,18 @@ TEST_P(PreluTest, Prelu) { } int main(int argc, char *argv[]) { + READY_TEST_CASE_GENERATE() + FOR_LOOP(lhs_shape, i) + FOR_LOOP(lhs_type, j) + FOR_LOOP(slope, k) + SPLIT_ELEMENT(lhs_shape, i) + SPLIT_ELEMENT(lhs_type, j) + SPLIT_ELEMENT(slope, k) + WRITE_SUB_CASE() + FOR_LOOP_END() + FOR_LOOP_END() + FOR_LOOP_END() + ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } \ No newline at end of file diff --git a/tests/kernels/test_prelu.json b/tests/kernels/test_prelu.json new file mode 100644 index 0000000000..b728e936d6 --- /dev/null +++ b/tests/kernels/test_prelu.json @@ -0,0 +1,5 @@ +{ + "lhs_shape":[[1, 3, 16, 16], [1, 3, 16], [8, 8], [1, 4, 16], [1], [1, 3, 24, 24]], + "lhs_type":["dt_float32"], + "slope":[[0.2], [0.1], [0.3], [0.2, 0.1, 0.3, 0.2, 0.1, 0.3, 0.2, 0.1, 0.3, 0.2, 0.1, 0.3, 0.2, 0.1, 0.3, 0.2, 0.1, 0.3, 0.2, 0.1, 0.3, 0.2, 0.1, 0.3], [0.1, 0.2, 0.2, 0.4, 0.2, 0.2, 0.3, 0.8], [0.1, 0.2, 0.2, 0.2, 0.1, 0.2, 0.2, 0.4, 0.1, 0.2, 0.2, 0.8, 0.2, 0.12, 0.2, 0.21], [0.1, 0.2, 0.3, 0.1, 0.2, 0.3, 0.1, 0.2]] +} \ No newline at end of file