From 4d90ce5b8aaade7ca1cce7d88b807f8b784984ad Mon Sep 17 00:00:00 2001 From: Stephanos Ioannidis Date: Sun, 22 Aug 2021 00:32:31 +0900 Subject: [PATCH] tests: lib: cmsis_dsp: support: Add barycenter F16 tests for 1.9.0 This commit updates the support barycenter F16 test patterns for the CMSIS-DSP 1.9.0. Signed-off-by: Stephanos Ioannidis --- tests/lib/cmsis_dsp/support/CMakeLists.txt | 1 + .../cmsis_dsp/support/src/barycenter_f16.c | 68 ++++++++++++++ .../cmsis_dsp/support/src/barycenter_f16.pat | 91 +++++++++++++++++++ tests/lib/cmsis_dsp/support/src/main.c | 4 + 4 files changed, 164 insertions(+) create mode 100644 tests/lib/cmsis_dsp/support/src/barycenter_f16.c create mode 100644 tests/lib/cmsis_dsp/support/src/barycenter_f16.pat diff --git a/tests/lib/cmsis_dsp/support/CMakeLists.txt b/tests/lib/cmsis_dsp/support/CMakeLists.txt index 6dcbae49583..6e15751cecc 100644 --- a/tests/lib/cmsis_dsp/support/CMakeLists.txt +++ b/tests/lib/cmsis_dsp/support/CMakeLists.txt @@ -15,4 +15,5 @@ target_sources(app PRIVATE target_sources_ifdef(CONFIG_CMSIS_DSP_FLOAT16 app PRIVATE src/f16.c + src/barycenter_f16.c ) diff --git a/tests/lib/cmsis_dsp/support/src/barycenter_f16.c b/tests/lib/cmsis_dsp/support/src/barycenter_f16.c new file mode 100644 index 00000000000..9245d1bec97 --- /dev/null +++ b/tests/lib/cmsis_dsp/support/src/barycenter_f16.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2021 Stephanos Ioannidis + * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include "../../common/test_common.h" + +#include "barycenter_f16.pat" + +#define ABS_ERROR_THRESH (1e-3) + +void test_arm_barycenter_f16(void) +{ + int test_index; + const size_t length = ARRAY_SIZE(ref_barycenter); + const uint16_t test_count = in_barycenter_dims[0]; + const uint16_t *dims = in_barycenter_dims + 1; + const float16_t *input_val = (const float16_t *)in_barycenter_val; + const float16_t *input_coeff = (const float16_t *)in_barycenter_coeff; + float16_t *output, *output_buf; + + /* Allocate output buffer */ + output_buf = malloc(length * sizeof(float16_t)); + zassert_not_null(output_buf, ASSERT_MSG_BUFFER_ALLOC_FAILED); + + output = output_buf; + + /* Enumerate tests */ + for (test_index = 0; test_index < test_count; test_index++) { + const uint16_t vec_count = dims[0]; + const uint16_t vec_length = dims[1]; + + /* Run test function */ + arm_barycenter_f16( + input_val, input_coeff, output, vec_count, vec_length); + + /* Increment pointers */ + input_val += vec_count * vec_length; + input_coeff += vec_count; + output += vec_length; + dims += 2; + } + + /* Validate output */ + zassert_true( + test_near_equal_f16( + length, output_buf, (float16_t *)ref_barycenter, + ABS_ERROR_THRESH), + ASSERT_MSG_ABS_ERROR_LIMIT_EXCEED); + + /* Free output buffer */ + free(output_buf); +} + +void test_support_barycenter_f16(void) +{ + ztest_test_suite(support_barycenter_f16, + ztest_unit_test(test_arm_barycenter_f16) + ); + + ztest_run_test_suite(support_barycenter_f16); +} diff --git a/tests/lib/cmsis_dsp/support/src/barycenter_f16.pat b/tests/lib/cmsis_dsp/support/src/barycenter_f16.pat new file mode 100644 index 00000000000..2496c83917b --- /dev/null +++ b/tests/lib/cmsis_dsp/support/src/barycenter_f16.pat @@ -0,0 +1,91 @@ +static const uint16_t in_barycenter_val[457] = { + 0x2ed1, 0x37f6, 0x3b20, 0x2e9b, 0x35bc, 0x3ad5, 0x342e, 0x3858, + 0x2f4b, 0x34ea, 0x3b1e, 0x37db, 0x37a6, 0x38db, 0x34b6, 0x3a43, + 0x3ad4, 0x3bfa, 0x375a, 0x3474, 0x3a7c, 0x3860, 0x3358, 0x3401, + 0x3846, 0x39e0, 0x348d, 0x38fb, 0x354e, 0x2e4e, 0x37b0, 0x30cd, + 0x3b36, 0x2e0f, 0x3813, 0x39b3, 0x340d, 0x3982, 0x28c3, 0x32f0, + 0x385d, 0x3599, 0x39b8, 0x3612, 0x35b2, 0x375b, 0x392d, 0x3bf1, + 0x3a9a, 0x3bc4, 0x3807, 0x39d1, 0x3835, 0x399c, 0x1d1f, 0x2fae, + 0x30ce, 0x3844, 0x3980, 0x3b24, 0x35ff, 0x3a62, 0x3bf6, 0x3999, + 0x38fc, 0x2862, 0x3549, 0x3889, 0x28ca, 0x3be6, 0x3a0c, 0x317f, + 0x2aa1, 0x34b0, 0x3872, 0x39a4, 0x248a, 0x3b8c, 0x356f, 0x3a0c, + 0x3b8e, 0x3ade, 0x2d96, 0x3a6a, 0x3672, 0x30ee, 0x3579, 0x3863, + 0x39a1, 0x3bdd, 0x3b6c, 0x39d8, 0x3a70, 0x3b50, 0x39f9, 0x3941, + 0x31b1, 0x31b3, 0x2a93, 0x36b7, 0x34f3, 0x3516, 0x3a3f, 0x323d, + 0x3b80, 0x38ce, 0x2d63, 0x3a10, 0x357a, 0x3b69, 0x3944, 0x3520, + 0x303f, 0x3b0b, 0x389e, 0x2a47, 0x3538, 0x30a1, 0x3ab3, 0x3105, + 0x34b5, 0x3b1d, 0x371c, 0x3940, 0x2f62, 0x38c9, 0x2c3d, 0x3bc4, + 0x2ee5, 0x3993, 0x3b7e, 0x34ae, 0x3b1d, 0x398c, 0x37e8, 0x37f0, + 0x3ae8, 0x3b36, 0x33bd, 0x397a, 0x398a, 0x2734, 0x393c, 0x37c8, + 0x31ea, 0x3bf6, 0x39d7, 0x3832, 0x39b7, 0x3bce, 0x3494, 0x38db, + 0x3959, 0x30de, 0x32e0, 0x385d, 0x3421, 0x3865, 0x3abb, 0x3210, + 0x3bf9, 0x349b, 0x3314, 0x3583, 0x3bf3, 0x3537, 0x3826, 0x3b98, + 0x38d8, 0x356e, 0x3350, 0x3809, 0x3782, 0x369d, 0x32c1, 0x39f1, + 0x305c, 0x394d, 0x3a45, 0x3498, 0x3451, 0x39de, 0x3b0b, 0x30ca, + 0x3490, 0x383c, 0x3668, 0x33e3, 0x35d1, 0x3bb1, 0x378f, 0x3b0c, + 0x3868, 0x3b61, 0x2fdd, 0x39f0, 0x3a0c, 0x3ad8, 0x385d, 0x372f, + 0x3b98, 0x33f1, 0x37e2, 0x3196, 0x38ad, 0x2c4c, 0x39a4, 0x3091, + 0x3a18, 0x3207, 0x3923, 0x2bbb, 0x362b, 0x3888, 0x3162, 0x3bf5, + 0x36ab, 0x3963, 0x3a1a, 0x3aad, 0x23d4, 0x38ce, 0x3b19, 0x3584, + 0x3b4a, 0x190f, 0x25e7, 0x3b63, 0x2ca8, 0x3abe, 0x3bd5, 0x370b, + 0x2e77, 0x368f, 0x34ac, 0x35ba, 0x3099, 0x357d, 0x3a55, 0x3997, + 0x2ef3, 0x36cd, 0x3356, 0x1d02, 0x2fdb, 0x3a85, 0x3999, 0x3b77, + 0x3692, 0x3908, 0x3677, 0x3b6a, 0x3ac5, 0x364d, 0x3b38, 0x3b04, + 0x3968, 0x383e, 0x39d5, 0x3121, 0x3622, 0x3b83, 0x394f, 0x302e, + 0x342a, 0x3759, 0x3bf5, 0x392b, 0x39a0, 0x3795, 0x3519, 0x3864, + 0x3a3d, 0x2f64, 0x3a1d, 0x3771, 0x3471, 0x32d2, 0x39b1, 0x368d, + 0x35fe, 0x36fa, 0x3a0c, 0x36bb, 0x2e93, 0x3acc, 0x2e9d, 0x2d08, + 0x3950, 0x3416, 0x3943, 0x252e, 0x31d4, 0x2e12, 0x38b8, 0x3396, + 0x33c4, 0x310c, 0x32b3, 0x2d5f, 0x30b2, 0x3865, 0x38d3, 0x39c0, + 0x3949, 0x3010, 0x33f0, 0x3070, 0x383a, 0x2bce, 0x344a, 0x3b4f, + 0x39d7, 0x344b, 0x35a8, 0x3823, 0x3b26, 0x3975, 0x2b11, 0x310b, + 0x3237, 0x2e8d, 0x3826, 0x3adb, 0x376f, 0x33c9, 0x33c5, 0x319a, + 0x3b67, 0x3677, 0x2f16, 0x340e, 0x3150, 0x3206, 0x30f8, 0x388d, + 0x1821, 0x387d, 0x3713, 0x213b, 0x3adb, 0x38cc, 0x37c0, 0x3b4e, + 0x373b, 0x3a32, 0x3ac2, 0x3aa5, 0x2f78, 0x2582, 0x2b39, 0x3afa, + 0x3bfd, 0x3844, 0x39de, 0x3916, 0x2c48, 0x1ad4, 0x3b9b, 0x3b20, + 0x3985, 0x3717, 0x3536, 0x34e0, 0x393c, 0x2fe0, 0x3711, 0x38ed, + 0x1dcf, 0x3946, 0x37c0, 0x3b4e, 0x3629, 0x37f1, 0x393f, 0x3bd9, + 0x3146, 0x38bf, 0x3705, 0x3967, 0x3814, 0x36f1, 0x395f, 0x2e39, + 0x3663, 0x3834, 0x39e9, 0x3890, 0x3b52, 0x36df, 0x3139, 0x3783, + 0x3839, 0x392b, 0x39d2, 0x38d6, 0x2c71, 0x3814, 0x34b4, 0x341e, + 0x38d0, 0x390a, 0x3472, 0x3859, 0x3874, 0x2d8f, 0x35e4, 0x3526, + 0x3118, 0x3bdd, 0x37b6, 0x37f3, 0x3748, 0x38db, 0x39b4, 0x3668, + 0x2cae, 0x37c0, 0x3add, 0x36ae, 0x3967, 0x3124, 0x390a, 0x30cc, + 0x2505, 0x3a71, 0x3b7b, 0x3b90, 0x3857, 0x3bc3, 0x3b87, 0x2ec5, + 0x3566, 0x39ae, 0x3a63, 0x394a, 0x3bc2, 0x3a7a, 0x3ad6, 0x3985, + 0x30ed, 0x389f, 0x3991, 0x32d6, 0x32e4, 0x3416, 0x2ea0, 0x2fb4, + 0x381c, 0x37b7, 0x3734, 0x3945, 0x3a25, 0x3890, 0x3921, 0x33a6, + 0x30e1 + }; + +static const uint16_t in_barycenter_coeff[67] = { + 0x38b1, 0x3bbd, 0x2ea6, 0x3a80, 0x399b, 0x2ca3, 0x269a, 0x3126, + 0x3731, 0x3970, 0x3503, 0x39f9, 0x2aab, 0x3a11, 0x3a00, 0x39df, + 0x3219, 0x35ce, 0x3b6a, 0x3bb8, 0x3896, 0x19e8, 0x32ee, 0x3bb0, + 0x34a4, 0x39df, 0x3a30, 0x3079, 0x339b, 0x39a5, 0x31a6, 0x38df, + 0x3b93, 0x39b9, 0x37d4, 0x3091, 0x3b6c, 0x2a8e, 0x3a95, 0x3ad0, + 0x3557, 0x36ae, 0x31ad, 0x3619, 0x3979, 0x3a5c, 0x3a5f, 0x34e9, + 0x34df, 0x3b05, 0x3861, 0x38ac, 0x2f56, 0x391d, 0x2d51, 0x3ad6, + 0x338b, 0x384d, 0x3a69, 0x3396, 0x2a74, 0x38c4, 0x3a1d, 0x2d19, + 0x3a92, 0x2aef, 0x2863 + }; + +static const uint16_t in_barycenter_dims[21] = { + 0x000A, 0x0004, 0x0004, 0x0008, 0x0004, 0x0009, 0x0004, 0x0004, + 0x0008, 0x0008, 0x0008, 0x0009, 0x0008, 0x0004, 0x0009, 0x0008, + 0x0009, 0x0009, 0x0009, 0x0004, 0x0004 + }; + +static const uint16_t ref_barycenter[67] = { + 0x353e, 0x3952, 0x372b, 0x381f, 0x386a, 0x3869, 0x3709, 0x3804, + 0x34b9, 0x396e, 0x378c, 0x3902, 0x3639, 0x3834, 0x3a01, 0x349d, + 0x3955, 0x38c1, 0x31b4, 0x388c, 0x381a, 0x3794, 0x3680, 0x392c, + 0x35f5, 0x38b6, 0x3850, 0x373b, 0x3417, 0x38d7, 0x3a44, 0x36f5, + 0x3802, 0x3629, 0x3544, 0x3720, 0x3821, 0x37d2, 0x3848, 0x3757, + 0x3886, 0x36db, 0x38df, 0x341e, 0x3644, 0x37ff, 0x37e8, 0x3828, + 0x3201, 0x372e, 0x3517, 0x3429, 0x382d, 0x380b, 0x35bb, 0x382d, + 0x38ee, 0x3736, 0x39ad, 0x38bb, 0x399e, 0x3883, 0x36f5, 0x34e0, + 0x320b, 0x312b, 0x37db + }; + diff --git a/tests/lib/cmsis_dsp/support/src/main.c b/tests/lib/cmsis_dsp/support/src/main.c index 105d0b536d1..d2ef12e37eb 100644 --- a/tests/lib/cmsis_dsp/support/src/main.c +++ b/tests/lib/cmsis_dsp/support/src/main.c @@ -12,6 +12,7 @@ extern void test_support_q15(void); extern void test_support_q31(void); extern void test_support_f16(void); extern void test_support_f32(void); +extern void test_support_barycenter_f16(void); extern void test_support_barycenter_f32(void); void test_main(void) @@ -23,5 +24,8 @@ void test_main(void) test_support_f16(); #endif test_support_f32(); +#ifdef CONFIG_CMSIS_DSP_FLOAT16 + test_support_barycenter_f16(); +#endif test_support_barycenter_f32(); }