1 #include "BinaryTestsF32.h"
2 #include <stdio.h>
3 #include "Error.h"
4
5 #define SNR_THRESHOLD 120
6
7 /*
8
9 Reference patterns are generated with
10 a double precision computation.
11
12 */
13 #define REL_ERROR (1.0e-6)
14 #define ABS_ERROR (1.0e-5)
15
16 /* Upper bound of maximum matrix dimension used by Python */
17 #define MAXMATRIXDIM 40
18
checkInnerTail(float32_t * b)19 static void checkInnerTail(float32_t *b)
20 {
21 ASSERT_TRUE(b[0] == 0);
22 ASSERT_TRUE(b[1] == 0);
23 ASSERT_TRUE(b[2] == 0);
24 ASSERT_TRUE(b[3] == 0);
25 }
26
27 #define LOADDATA2() \
28 const float32_t *inp1=input1.ptr(); \
29 const float32_t *inp2=input2.ptr(); \
30 \
31 float32_t *ap=a.ptr(); \
32 float32_t *bp=b.ptr(); \
33 \
34 float32_t *outp=output.ptr(); \
35 int16_t *dimsp = dims.ptr(); \
36 int nbMatrixes = dims.nbSamples() / 3;\
37 int rows,internal,columns; \
38 int i;
39
40
41
42
43
44 #define PREPAREDATA2() \
45 in1.numRows=rows; \
46 in1.numCols=internal; \
47 memcpy((void*)ap,(const void*)inp1,2*sizeof(float32_t)*rows*internal);\
48 in1.pData = ap; \
49 \
50 in2.numRows=internal; \
51 in2.numCols=columns; \
52 memcpy((void*)bp,(const void*)inp2,2*sizeof(float32_t)*internal*columns);\
53 in2.pData = bp; \
54 \
55 out.numRows=rows; \
56 out.numCols=columns; \
57 out.pData = outp;
58
59
60
test_mat_mult_f32()61 void BinaryTestsF32::test_mat_mult_f32()
62 {
63 LOADDATA2();
64 arm_status status;
65
66 for(i=0;i < nbMatrixes ; i ++)
67 {
68 rows = *dimsp++;
69 internal = *dimsp++;
70 columns = *dimsp++;
71
72 PREPAREDATA2();
73
74 status=arm_mat_mult_f32(&this->in1,&this->in2,&this->out);
75 ASSERT_TRUE(status==ARM_MATH_SUCCESS);
76
77 outp += (rows * columns);
78 checkInnerTail(outp);
79
80 }
81
82 ASSERT_EMPTY_TAIL(output);
83
84 ASSERT_SNR(output,ref,(float32_t)SNR_THRESHOLD);
85
86 ASSERT_CLOSE_ERROR(output,ref,ABS_ERROR,REL_ERROR);
87
88 }
89
90
91
test_mat_cmplx_mult_f32()92 void BinaryTestsF32::test_mat_cmplx_mult_f32()
93 {
94 LOADDATA2();
95 arm_status status;
96
97 for(i=0;i < nbMatrixes ; i ++)
98 {
99 rows = *dimsp++;
100 internal = *dimsp++;
101 columns = *dimsp++;
102
103
104 PREPAREDATA2();
105
106 status=arm_mat_cmplx_mult_f32(&this->in1,&this->in2,&this->out);
107 ASSERT_TRUE(status==ARM_MATH_SUCCESS);
108
109 outp += (2*rows * columns);
110 checkInnerTail(outp);
111
112 }
113
114 ASSERT_EMPTY_TAIL(output);
115
116 ASSERT_SNR(output,ref,(float32_t)SNR_THRESHOLD);
117
118 ASSERT_CLOSE_ERROR(output,ref,ABS_ERROR,REL_ERROR);
119
120 }
121
122
setUp(Testing::testID_t id,std::vector<Testing::param_t> & params,Client::PatternMgr * mgr)123 void BinaryTestsF32::setUp(Testing::testID_t id,std::vector<Testing::param_t>& params,Client::PatternMgr *mgr)
124 {
125
126
127 (void)params;
128 switch(id)
129 {
130 case TEST_MAT_MULT_F32_1:
131 input1.reload(BinaryTestsF32::INPUTS1_F32_ID,mgr);
132 input2.reload(BinaryTestsF32::INPUTS2_F32_ID,mgr);
133 dims.reload(BinaryTestsF32::DIMSBINARY1_S16_ID,mgr);
134
135 ref.reload(BinaryTestsF32::REFMUL1_F32_ID,mgr);
136
137 output.create(ref.nbSamples(),BinaryTestsF32::OUT_F32_ID,mgr);
138 a.create(MAXMATRIXDIM*MAXMATRIXDIM,BinaryTestsF32::TMPA_F32_ID,mgr);
139 b.create(MAXMATRIXDIM*MAXMATRIXDIM,BinaryTestsF32::TMPB_F32_ID,mgr);
140 break;
141
142 case TEST_MAT_CMPLX_MULT_F32_2:
143 input1.reload(BinaryTestsF32::INPUTSC1_F32_ID,mgr);
144 input2.reload(BinaryTestsF32::INPUTSC2_F32_ID,mgr);
145 dims.reload(BinaryTestsF32::DIMSBINARY1_S16_ID,mgr);
146
147 ref.reload(BinaryTestsF32::REFCMPLXMUL1_F32_ID,mgr);
148
149 output.create(ref.nbSamples(),BinaryTestsF32::OUT_F32_ID,mgr);
150 a.create(2*MAXMATRIXDIM*MAXMATRIXDIM,BinaryTestsF32::TMPA_F32_ID,mgr);
151 b.create(2*MAXMATRIXDIM*MAXMATRIXDIM,BinaryTestsF32::TMPB_F32_ID,mgr);
152 break;
153
154
155
156
157 }
158
159
160
161 }
162
tearDown(Testing::testID_t id,Client::PatternMgr * mgr)163 void BinaryTestsF32::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
164 {
165 (void)id;
166 output.dump(mgr);
167 }
168