1 /*
2 * Copyright (c) 2021 Stephanos Ioannidis <root@stephanos.io>
3 * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8 #include <zephyr/ztest.h>
9 #include <zephyr/kernel.h>
10 #include <stdlib.h>
11 #include <arm_math_f16.h>
12 #include "../../common/test_common.h"
13
14 #include "f16.pat"
15
16 #define SNR_ERROR_THRESH ((float16_t)55)
17 #define REL_ERROR_THRESH (5.0e-3)
18 #define ABS_ERROR_THRESH (5.0e-3)
19
ZTEST(interpolation_f16,test_arm_linear_interp_f16)20 ZTEST(interpolation_f16, test_arm_linear_interp_f16)
21 {
22 arm_linear_interp_instance_f16 inst;
23 size_t index;
24 size_t length = ARRAY_SIZE(ref_linear);
25 const float16_t *input = (const float16_t *)in_linear_x;
26 float16_t *output;
27
28 /* Initialise instance */
29 inst.nValues = ARRAY_SIZE(in_linear_y);
30 inst.x1 = 0.0;
31 inst.xSpacing = 1.0;
32 inst.pYData = (float16_t *)in_linear_y;
33
34 /* Allocate output buffer */
35 output = malloc(length * sizeof(float16_t));
36 zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED);
37
38 /* Run test function */
39 for (index = 0; index < length; index++) {
40 output[index] = arm_linear_interp_f16(&inst,
41 input[index]);
42 }
43
44 /* Validate output */
45 zassert_true(
46 test_snr_error_f16(length, output, (float16_t *)ref_linear,
47 SNR_ERROR_THRESH),
48 ASSERT_MSG_SNR_LIMIT_EXCEED);
49
50 zassert_true(
51 test_close_error_f16(length, output, (float16_t *)ref_linear,
52 ABS_ERROR_THRESH, REL_ERROR_THRESH),
53 ASSERT_MSG_ERROR_LIMIT_EXCEED);
54
55 /* Free output buffer */
56 free(output);
57 }
58
ZTEST(interpolation_f16,test_arm_bilinear_interp_f16)59 ZTEST(interpolation_f16, test_arm_bilinear_interp_f16)
60 {
61 arm_bilinear_interp_instance_f16 inst;
62 size_t index;
63 size_t length = ARRAY_SIZE(ref_bilinear);
64 const float16_t *input = (const float16_t *)in_bilinear_x;
65 float16_t *output;
66
67 /* Initialise instance */
68 inst.numRows = in_bilinear_config[1];
69 inst.numCols = in_bilinear_config[0];
70 inst.pData = (float16_t *)in_bilinear_y;
71
72 /* Allocate output buffer */
73 output = malloc(length * sizeof(float16_t));
74 zassert_not_null(output, ASSERT_MSG_BUFFER_ALLOC_FAILED);
75
76 /* Run test function */
77 for (index = 0; index < length; index++) {
78 output[index] = arm_bilinear_interp_f16(
79 &inst,
80 input[2 * index],
81 input[2 * index + 1]
82 );
83 }
84
85 /* Validate output */
86 zassert_true(
87 test_snr_error_f16(length, output, (float16_t *)ref_bilinear,
88 SNR_ERROR_THRESH),
89 ASSERT_MSG_SNR_LIMIT_EXCEED);
90
91 zassert_true(
92 test_close_error_f16(length, output, (float16_t *)ref_bilinear,
93 ABS_ERROR_THRESH, REL_ERROR_THRESH),
94 ASSERT_MSG_ERROR_LIMIT_EXCEED);
95
96 /* Free output buffer */
97 free(output);
98 }
99
100 ZTEST_SUITE(interpolation_f16, NULL, NULL, NULL, NULL, NULL);
101