1 #include "InterpolationTestsF16.h"
2 #include <stdio.h>
3 #include "Error.h"
4 
5 #define SNR_THRESHOLD 44
6 
7 /*
8 
9 Reference patterns are generated with
10 a double precision computation.
11 
12 */
13 
14 #define REL_ERROR (6.0e-3)
15 #define ABS_ERROR (7.0e-3)
16 
17 
18 
test_linear_interp_f16()19     void InterpolationTestsF16::test_linear_interp_f16()
20     {
21        const float16_t *inp = input.ptr();
22        float16_t *outp = output.ptr();
23 
24        unsigned long nb;
25        for(nb = 0; nb < input.nbSamples(); nb++)
26        {
27           outp[nb] = arm_linear_interp_f16(&S,inp[nb]);
28        }
29 
30        ASSERT_EMPTY_TAIL(output);
31 
32        ASSERT_SNR(output,ref,(float16_t)SNR_THRESHOLD);
33 
34        ASSERT_CLOSE_ERROR(output,ref,ABS_ERROR,REL_ERROR);
35 
36     }
37 
38 
test_bilinear_interp_f16()39     void InterpolationTestsF16::test_bilinear_interp_f16()
40     {
41        const float16_t *inp = input.ptr();
42        float16_t *outp = output.ptr();
43        float16_t x,y;
44        unsigned long nb;
45        for(nb = 0; nb < input.nbSamples(); nb += 2)
46        {
47           x = inp[nb];
48           y = inp[nb+1];
49           *outp++=arm_bilinear_interp_f16(&SBI,x,y);
50        }
51 
52        ASSERT_EMPTY_TAIL(output);
53 
54        ASSERT_SNR(output,ref,(float16_t)SNR_THRESHOLD);
55 
56        ASSERT_CLOSE_ERROR(output,ref,ABS_ERROR,REL_ERROR);
57 
58     }
59 
60  #if 0
61     void InterpolationTestsF16::test_spline_square_f16()
62     {
63        const float16_t *inpX = inputX.ptr();
64        const float16_t *inpY = inputY.ptr();
65        const float16_t *outX = outputX.ptr();
66        float16_t *outp = output.ptr();
67        float16_t *buf = buffer.ptr();       // ((2*4-1)*sizeof(float16_t))
68        float16_t *coef = splineCoefs.ptr(); // ((3*(4-1))*sizeof(float16_t))
69 
70        arm_spline_instance_f16 S;
71        arm_spline_init_f16(&S, ARM_SPLINE_PARABOLIC_RUNOUT, inpX, inpY, 4, coef, buf);
72        arm_spline_f16(&S, outX, outp, 20);
73 
74        ASSERT_EMPTY_TAIL(buffer);
75        ASSERT_EMPTY_TAIL(splineCoefs);
76        ASSERT_EMPTY_TAIL(output);
77        ASSERT_SNR(output,ref,(float16_t)SNR_THRESHOLD);
78     }
79 
80     void InterpolationTestsF16::test_spline_sine_f16()
81     {
82        const float16_t *inpX = inputX.ptr();
83        const float16_t *inpY = inputY.ptr();
84        const float16_t *outX = outputX.ptr();
85        float16_t *outp = output.ptr();
86        float16_t *buf = buffer.ptr(); // ((2*9-1)*sizeof(float16_t))
87        float16_t *coef = splineCoefs.ptr(); // ((3*(9-1))*sizeof(float16_t))
88 
89        arm_spline_instance_f16 S;
90        arm_spline_init_f16(&S, ARM_SPLINE_NATURAL, inpX, inpY, 9, coef, buf);
91        arm_spline_f16(&S, outX, outp, 33);
92 
93        ASSERT_EMPTY_TAIL(buffer);
94        ASSERT_EMPTY_TAIL(splineCoefs);
95        ASSERT_EMPTY_TAIL(output);
96        ASSERT_SNR(output,ref,(float16_t)SNR_THRESHOLD);
97     }
98 
99     void InterpolationTestsF16::test_spline_ramp_f16()
100     {
101        const float16_t *inpX = inputX.ptr();
102        const float16_t *inpY = inputY.ptr();
103        const float16_t *outX = outputX.ptr();
104        float16_t *outp = output.ptr();
105        float16_t *buf = buffer.ptr(); // ((2*3-1)*sizeof(float16_t))
106        float16_t *coef = splineCoefs.ptr(); // ((3*(3-1))*sizeof(float16_t))
107 
108        arm_spline_instance_f16 S;
109        arm_spline_init_f16(&S, ARM_SPLINE_PARABOLIC_RUNOUT, inpX, inpY, 3, coef, buf);
110        arm_spline_f16(&S, outX, outp, 30);
111 
112        ASSERT_EMPTY_TAIL(buffer);
113        ASSERT_EMPTY_TAIL(splineCoefs);
114        ASSERT_EMPTY_TAIL(output);
115        ASSERT_SNR(output,ref,(float16_t)SNR_THRESHOLD);
116     }
117 #endif
118 
setUp(Testing::testID_t id,std::vector<Testing::param_t> & params,Client::PatternMgr * mgr)119     void InterpolationTestsF16::setUp(Testing::testID_t id,std::vector<Testing::param_t>& params,Client::PatternMgr *mgr)
120     {
121 
122        const int16_t *pConfig;
123        Testing::nbSamples_t nb=MAX_NB_SAMPLES;
124        (void)params;
125 
126 
127        switch(id)
128        {
129         case InterpolationTestsF16::TEST_LINEAR_INTERP_F16_1:
130           input.reload(InterpolationTestsF16::INPUT_F16_ID,mgr,nb);
131           y.reload(InterpolationTestsF16::YVAL_F16_ID,mgr,nb);
132           ref.reload(InterpolationTestsF16::REF_LINEAR_F16_ID,mgr,nb);
133 
134 
135           S.nValues=y.nbSamples();           /**< nValues */
136           /* Those values must be coherent with the ones in the
137           Python script generating the patterns */
138           S.x1=0.0;               /**< x1 */
139           S.xSpacing=1.0;         /**< xSpacing */
140           S.pYData=y.ptr();          /**< pointer to the table of Y values */
141           break;
142 
143          case InterpolationTestsF16::TEST_BILINEAR_INTERP_F16_2:
144           input.reload(InterpolationTestsF16::INPUTBI_F16_ID,mgr,nb);
145           config.reload(InterpolationTestsF16::CONFIGBI_S16_ID,mgr,nb);
146           y.reload(InterpolationTestsF16::YVALBI_F16_ID,mgr,nb);
147           ref.reload(InterpolationTestsF16::REF_BILINEAR_F16_ID,mgr,nb);
148 
149           pConfig = config.ptr();
150 
151           SBI.numRows = pConfig[1];
152           SBI.numCols = pConfig[0];
153 
154           SBI.pData = y.ptr();
155 
156           break;
157 #if 0
158           case TEST_SPLINE_SQUARE_F16_3:
159              inputX.reload(InterpolationTestsF16::INPUT_SPLINE_SQU_X_F16_ID,mgr,4);
160              inputY.reload(InterpolationTestsF16::INPUT_SPLINE_SQU_Y_F16_ID,mgr,4);
161              outputX.reload(InterpolationTestsF16::OUTPUT_SPLINE_SQU_X_F16_ID,mgr,20);
162              ref.reload(InterpolationTestsF16::REF_SPLINE_SQU_F16_ID,mgr,20);
163              splineCoefs.create(3*(4-1),InterpolationTestsF16::COEFS_SPLINE_F16_ID,mgr);
164 
165              buffer.create(2*4-1,InterpolationTestsF16::TEMP_SPLINE_F16_ID,mgr);
166              output.create(20,InterpolationTestsF16::OUT_SAMPLES_F16_ID,mgr);
167           break;
168 
169           case TEST_SPLINE_SINE_F16_4:
170              inputX.reload(InterpolationTestsF16::INPUT_SPLINE_SIN_X_F16_ID,mgr,9);
171              inputY.reload(InterpolationTestsF16::INPUT_SPLINE_SIN_Y_F16_ID,mgr,9);
172              outputX.reload(InterpolationTestsF16::OUTPUT_SPLINE_SIN_X_F16_ID,mgr,33);
173              ref.reload(InterpolationTestsF16::REF_SPLINE_SIN_F16_ID,mgr,33);
174              splineCoefs.create(3*(9-1),InterpolationTestsF16::COEFS_SPLINE_F16_ID,mgr);
175 
176              buffer.create(2*9-1,InterpolationTestsF16::TEMP_SPLINE_F16_ID,mgr);
177              output.create(33,InterpolationTestsF16::OUT_SAMPLES_F16_ID,mgr);
178           break;
179 
180           case TEST_SPLINE_RAMP_F16_5:
181              inputX.reload(InterpolationTestsF16::INPUT_SPLINE_RAM_X_F16_ID,mgr,3);
182              inputY.reload(InterpolationTestsF16::INPUT_SPLINE_RAM_Y_F16_ID,mgr,3);
183              outputX.reload(InterpolationTestsF16::OUTPUT_SPLINE_RAM_X_F16_ID,mgr,30);
184              ref.reload(InterpolationTestsF16::REF_SPLINE_RAM_F16_ID,mgr,30);
185              splineCoefs.create(3*(3-1),InterpolationTestsF16::COEFS_SPLINE_F16_ID,mgr);
186 
187              buffer.create(2*3-1,InterpolationTestsF16::TEMP_SPLINE_F16_ID,mgr);
188              output.create(30,InterpolationTestsF16::OUT_SAMPLES_F16_ID,mgr);
189           break;
190 #endif
191        }
192 
193 
194 
195        output.create(ref.nbSamples(),InterpolationTestsF16::OUT_SAMPLES_F16_ID,mgr);
196     }
197 
tearDown(Testing::testID_t id,Client::PatternMgr * mgr)198     void InterpolationTestsF16::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
199     {
200         (void)id;
201         output.dump(mgr);
202     }
203