1 #include "SVMF16.h"
2 #include <stdio.h>
3 #include "Error.h"
4 
5 
test_svm_linear_predict_f16()6 void SVMF16::test_svm_linear_predict_f16()
7 {
8       const float16_t *inp  = samples.ptr();
9       int32_t *outp         = output.ptr();
10       int32_t *result;
11 
12       result=outp;
13 
14       for(int i =0; i < this->nbTestSamples; i++)
15       {
16          arm_svm_linear_predict_f16(&this->linear,inp,result);
17          result++;
18          inp += this->vecDim;
19       }
20 
21       ASSERT_EQ(ref,output);
22 
23 }
24 
25 
test_svm_polynomial_predict_f16()26 void SVMF16::test_svm_polynomial_predict_f16()
27 {
28       const float16_t *inp  = samples.ptr();
29       int32_t *outp         = output.ptr();
30       int32_t *result;
31 
32       result=outp;
33 
34       for(int i =0; i < this->nbTestSamples; i++)
35       {
36          arm_svm_polynomial_predict_f16(&this->poly,inp,result);
37          result++;
38          inp += this->vecDim;
39       }
40 
41       ASSERT_EQ(ref,output);
42 
43 }
44 
test_svm_rbf_predict_f16()45 void SVMF16::test_svm_rbf_predict_f16()
46 {
47       const float16_t *inp  = samples.ptr();
48       int32_t *outp         = output.ptr();
49       int32_t *result;
50 
51       result=outp;
52 
53       for(int i =0; i < this->nbTestSamples; i++)
54       {
55          arm_svm_rbf_predict_f16(&this->rbf,inp,result);
56          result++;
57          inp += this->vecDim;
58       }
59 
60       ASSERT_EQ(ref,output);
61 
62 }
63 
test_svm_sigmoid_predict_f16()64 void SVMF16::test_svm_sigmoid_predict_f16()
65 {
66       const float16_t *inp  = samples.ptr();
67       int32_t *outp         = output.ptr();
68       int32_t *result;
69 
70       result=outp;
71 
72       for(int i =0; i < this->nbTestSamples; i++)
73       {
74          arm_svm_sigmoid_predict_f16(&this->sigmoid,inp,result);
75          result++;
76          inp += this->vecDim;
77       }
78 
79       ASSERT_EQ(ref,output);
80 
81 }
82 
83 
84 
setUp(Testing::testID_t id,std::vector<Testing::param_t> & testparams,Client::PatternMgr * mgr)85 void SVMF16::setUp(Testing::testID_t id,std::vector<Testing::param_t>& testparams,Client::PatternMgr *mgr)
86 {
87 
88       int kind;
89       Testing::nbSamples_t nb=MAX_NB_SAMPLES;
90       (void)testparams;
91 
92       switch(id)
93       {
94           case SVMF16::TEST_SVM_LINEAR_PREDICT_F16_1:
95           {
96 
97              samples.reload(SVMF16::SAMPLES1_F16_ID,mgr,nb);
98              params.reload(SVMF16::PARAMS1_F16_ID,mgr,nb);
99              dims.reload(SVMF16::DIMS1_S16_ID,mgr,nb);
100              ref.reload(SVMF16::REF1_S32_ID,mgr,nb);
101           }
102           break;
103 
104           case SVMF16::TEST_SVM_POLYNOMIAL_PREDICT_F16_2:
105           {
106 
107              samples.reload(SVMF16::SAMPLES2_F16_ID,mgr,nb);
108              params.reload(SVMF16::PARAMS2_F16_ID,mgr,nb);
109              dims.reload(SVMF16::DIMS2_S16_ID,mgr,nb);
110              ref.reload(SVMF16::REF2_S32_ID,mgr,nb);
111           }
112           break;
113 
114           case SVMF16::TEST_SVM_RBF_PREDICT_F16_3:
115           {
116 
117              samples.reload(SVMF16::SAMPLES3_F16_ID,mgr,nb);
118              params.reload(SVMF16::PARAMS3_F16_ID,mgr,nb);
119              dims.reload(SVMF16::DIMS3_S16_ID,mgr,nb);
120              ref.reload(SVMF16::REF3_S32_ID,mgr,nb);
121           }
122           break;
123 
124           case SVMF16::TEST_SVM_SIGMOID_PREDICT_F16_4:
125           {
126 
127              samples.reload(SVMF16::SAMPLES4_F16_ID,mgr,nb);
128              params.reload(SVMF16::PARAMS4_F16_ID,mgr,nb);
129              dims.reload(SVMF16::DIMS4_S16_ID,mgr,nb);
130              ref.reload(SVMF16::REF4_S32_ID,mgr,nb);
131           }
132           break;
133 #if 0
134           case SVMF16::TEST_SVM_RBF_PREDICT_F16_5:
135           {
136 
137              samples.reload(SVMF16::SAMPLES5_F16_ID,mgr,nb);
138              params.reload(SVMF16::PARAMS5_F16_ID,mgr,nb);
139              dims.reload(SVMF16::DIMS5_S16_ID,mgr,nb);
140              ref.reload(SVMF16::REF5_S32_ID,mgr,nb);
141           }
142           break;
143 #endif
144       }
145 
146 
147 
148 
149       const int16_t   *dimsp = dims.ptr();
150       const float16_t  *paramsp = params.ptr();
151 
152       kind = dimsp[0];
153 
154       this->classes[0] = dimsp[1];
155       this->classes[1] = dimsp[2];
156       this->nbTestSamples=dimsp[3];
157       this->vecDim = dimsp[4];
158       this->nbSupportVectors = dimsp[5];
159       this->intercept=paramsp[this->vecDim*this->nbSupportVectors + this->nbSupportVectors];
160       this->supportVectors=paramsp;
161       this->dualCoefs=paramsp + (this->vecDim*this->nbSupportVectors);
162 
163       switch(kind)
164       {
165 
166 
167          case SVMF16::POLY:
168              this->degree = dimsp[6];
169              this->coef0 =paramsp[this->vecDim*this->nbSupportVectors + this->nbSupportVectors + 1] ;
170              this->gamma=paramsp[this->vecDim*this->nbSupportVectors + this->nbSupportVectors + 2];
171          break;
172 
173          case SVMF16::RBF:
174              this->gamma=paramsp[this->vecDim*this->nbSupportVectors + this->nbSupportVectors + 1];
175          break;
176 
177          case SVMF16::SIGMOID:
178              this->coef0 =paramsp[this->vecDim*this->nbSupportVectors + this->nbSupportVectors + 1] ;
179              this->gamma=paramsp[this->vecDim*this->nbSupportVectors + this->nbSupportVectors + 2];
180          break;
181       }
182 
183 
184        switch(id)
185        {
186           case SVMF16::TEST_SVM_LINEAR_PREDICT_F16_1:
187           //case SVMF16::TEST_SVM_RBF_PREDICT_F16_5:
188           {
189 
190              arm_svm_linear_init_f16(&linear,
191                  this->nbSupportVectors,
192                  this->vecDim,
193                  this->intercept,
194                  this->dualCoefs,
195                  this->supportVectors,
196                  this->classes);
197           }
198           break;
199 
200           case SVMF16::TEST_SVM_POLYNOMIAL_PREDICT_F16_2:
201           {
202 
203              arm_svm_polynomial_init_f16(&poly,
204                  this->nbSupportVectors,
205                  this->vecDim,
206                  this->intercept,
207                  this->dualCoefs,
208                  this->supportVectors,
209                  this->classes,
210                  this->degree,
211                  this->coef0,
212                  this->gamma
213                  );
214           }
215           break;
216 
217           case SVMF16::TEST_SVM_RBF_PREDICT_F16_3:
218           {
219 
220              arm_svm_rbf_init_f16(&rbf,
221                  this->nbSupportVectors,
222                  this->vecDim,
223                  this->intercept,
224                  this->dualCoefs,
225                  this->supportVectors,
226                  this->classes,
227                  this->gamma
228                  );
229           }
230           break;
231 
232           case SVMF16::TEST_SVM_SIGMOID_PREDICT_F16_4:
233           {
234 
235              arm_svm_sigmoid_init_f16(&sigmoid,
236                  this->nbSupportVectors,
237                  this->vecDim,
238                  this->intercept,
239                  this->dualCoefs,
240                  this->supportVectors,
241                  this->classes,
242                  this->coef0,
243                  this->gamma
244                  );
245           }
246           break;
247        }
248 
249 
250        output.create(ref.nbSamples(),SVMF16::OUT_S32_ID,mgr);
251 
252 }
253 
tearDown(Testing::testID_t id,Client::PatternMgr * mgr)254 void SVMF16::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
255 {
256         (void)id;
257         output.dump(mgr);
258 }
259 
260 
261 
262