1 #include "DistanceTestsF64.h" 2 #include <stdio.h> 3 #include "Error.h" 4 #include "Test.h" 5 6 7 #define REL_ERROR (2.0e-14) 8 9 /* 10 void DistanceTestsF64::test_braycurtis_distance_f64() 11 { 12 const float64_t *inpA = inputA.ptr(); 13 const float64_t *inpB = inputB.ptr(); 14 15 float64_t *outp = output.ptr(); 16 17 for(int i=0; i < this->nbPatterns ; i ++) 18 { 19 *outp = arm_braycurtis_distance_f64(inpA, inpB, this->vecDim); 20 21 inpA += this->vecDim; 22 inpB += this->vecDim; 23 outp ++; 24 } 25 26 ASSERT_NEAR_EQ(output,ref,(float64_t)1e-3); 27 } 28 29 void DistanceTestsF64::test_canberra_distance_f64() 30 { 31 const float64_t *inpA = inputA.ptr(); 32 const float64_t *inpB = inputB.ptr(); 33 34 float64_t *outp = output.ptr(); 35 36 for(int i=0; i < this->nbPatterns ; i ++) 37 { 38 *outp = arm_canberra_distance_f64(inpA, inpB, this->vecDim); 39 40 inpA += this->vecDim; 41 inpB += this->vecDim; 42 outp ++; 43 } 44 45 ASSERT_NEAR_EQ(output,ref,(float64_t)1e-3); 46 } 47 */ test_chebyshev_distance_f64()48 void DistanceTestsF64::test_chebyshev_distance_f64() 49 { 50 const float64_t *inpA = inputA.ptr(); 51 const float64_t *inpB = inputB.ptr(); 52 53 float64_t *outp = output.ptr(); 54 55 for(int i=0; i < this->nbPatterns ; i ++) 56 { 57 *outp = arm_chebyshev_distance_f64(inpA, inpB, this->vecDim); 58 59 inpA += this->vecDim; 60 inpB += this->vecDim; 61 outp ++; 62 } 63 64 ASSERT_NEAR_EQ(output,ref,(float64_t)REL_ERROR); 65 } 66 test_cityblock_distance_f64()67 void DistanceTestsF64::test_cityblock_distance_f64() 68 { 69 const float64_t *inpA = inputA.ptr(); 70 const float64_t *inpB = inputB.ptr(); 71 72 float64_t *outp = output.ptr(); 73 74 for(int i=0; i < this->nbPatterns ; i ++) 75 { 76 *outp = arm_cityblock_distance_f64(inpA, inpB, this->vecDim); 77 78 inpA += this->vecDim; 79 inpB += this->vecDim; 80 outp ++; 81 } 82 83 ASSERT_NEAR_EQ(output,ref,(float64_t)REL_ERROR); 84 } 85 86 /* 87 void DistanceTestsF64::test_correlation_distance_f64() 88 { 89 const float64_t *inpA = inputA.ptr(); 90 const float64_t *inpB = inputB.ptr(); 91 92 float64_t *tmpap = tmpA.ptr(); 93 float64_t *tmpbp = tmpB.ptr(); 94 95 float64_t *outp = output.ptr(); 96 97 for(int i=0; i < this->nbPatterns ; i ++) 98 { 99 memcpy(tmpap, inpA, sizeof(float64_t) * this->vecDim); 100 memcpy(tmpbp, inpB, sizeof(float64_t) * this->vecDim); 101 102 *outp = arm_correlation_distance_f64(tmpap, tmpbp, this->vecDim); 103 104 inpA += this->vecDim; 105 inpB += this->vecDim; 106 outp ++; 107 } 108 109 ASSERT_NEAR_EQ(output,ref,(float64_t)1e-3); 110 } 111 */ test_cosine_distance_f64()112 void DistanceTestsF64::test_cosine_distance_f64() 113 { 114 const float64_t *inpA = inputA.ptr(); 115 const float64_t *inpB = inputB.ptr(); 116 117 float64_t *outp = output.ptr(); 118 119 for(int i=0; i < this->nbPatterns ; i ++) 120 { 121 *outp = arm_cosine_distance_f64(inpA, inpB, this->vecDim); 122 123 inpA += this->vecDim; 124 inpB += this->vecDim; 125 outp ++; 126 } 127 128 ASSERT_NEAR_EQ(output,ref,(float64_t)REL_ERROR); 129 } 130 test_euclidean_distance_f64()131 void DistanceTestsF64::test_euclidean_distance_f64() 132 { 133 const float64_t *inpA = inputA.ptr(); 134 const float64_t *inpB = inputB.ptr(); 135 136 float64_t *outp = output.ptr(); 137 138 for(int i=0; i < this->nbPatterns ; i ++) 139 { 140 *outp = arm_euclidean_distance_f64(inpA, inpB, this->vecDim); 141 142 inpA += this->vecDim; 143 inpB += this->vecDim; 144 outp ++; 145 } 146 147 ASSERT_NEAR_EQ(output,ref,(float64_t)REL_ERROR); 148 } 149 /* 150 void DistanceTestsF64::test_jensenshannon_distance_f64() 151 { 152 const float64_t *inpA = inputA.ptr(); 153 const float64_t *inpB = inputB.ptr(); 154 155 float64_t *outp = output.ptr(); 156 157 158 159 for(int i=0; i < this->nbPatterns ; i ++) 160 { 161 *outp = arm_jensenshannon_distance_f64(inpA, inpB, this->vecDim); 162 163 inpA += this->vecDim; 164 inpB += this->vecDim; 165 outp ++; 166 } 167 168 ASSERT_NEAR_EQ(output,ref,(float64_t)1e-3); 169 } 170 171 void DistanceTestsF64::test_minkowski_distance_f64() 172 { 173 const float64_t *inpA = inputA.ptr(); 174 const float64_t *inpB = inputB.ptr(); 175 const int16_t *dimsp= dims.ptr(); 176 dimsp += 2; 177 178 float64_t *outp = output.ptr(); 179 180 for(int i=0; i < this->nbPatterns ; i ++) 181 { 182 *outp = arm_minkowski_distance_f64(inpA, inpB, *dimsp,this->vecDim); 183 184 inpA += this->vecDim; 185 inpB += this->vecDim; 186 outp ++; 187 dimsp ++; 188 } 189 190 ASSERT_NEAR_EQ(output,ref,(float64_t)1e-3); 191 } 192 193 */ setUp(Testing::testID_t id,std::vector<Testing::param_t> & paramsArgs,Client::PatternMgr * mgr)194 void DistanceTestsF64::setUp(Testing::testID_t id,std::vector<Testing::param_t>& paramsArgs,Client::PatternMgr *mgr) 195 { 196 197 (void)paramsArgs; 198 if ((id != DistanceTestsF64::TEST_MINKOWSKI_DISTANCE_F64_9) && (id != DistanceTestsF64::TEST_JENSENSHANNON_DISTANCE_F64_8)) 199 { 200 inputA.reload(DistanceTestsF64::INPUTA_F64_ID,mgr); 201 inputB.reload(DistanceTestsF64::INPUTB_F64_ID,mgr); 202 dims.reload(DistanceTestsF64::DIMS_S16_ID,mgr); 203 204 const int16_t *dimsp = dims.ptr(); 205 206 this->nbPatterns=dimsp[0]; 207 this->vecDim=dimsp[1]; 208 output.create(this->nbPatterns,DistanceTestsF64::OUT_F64_ID,mgr); 209 } 210 211 switch(id) 212 { 213 case DistanceTestsF64::TEST_BRAYCURTIS_DISTANCE_F64_1: 214 { 215 ref.reload(DistanceTestsF64::REF1_F64_ID,mgr); 216 } 217 break; 218 219 case DistanceTestsF64::TEST_CANBERRA_DISTANCE_F64_2: 220 { 221 ref.reload(DistanceTestsF64::REF2_F64_ID,mgr); 222 } 223 break; 224 225 case DistanceTestsF64::TEST_CHEBYSHEV_DISTANCE_F64_3: 226 { 227 ref.reload(DistanceTestsF64::REF3_F64_ID,mgr); 228 } 229 break; 230 231 case DistanceTestsF64::TEST_CITYBLOCK_DISTANCE_F64_4: 232 { 233 ref.reload(DistanceTestsF64::REF4_F64_ID,mgr); 234 } 235 break; 236 237 case DistanceTestsF64::TEST_CORRELATION_DISTANCE_F64_5: 238 { 239 ref.reload(DistanceTestsF64::REF5_F64_ID,mgr); 240 tmpA.create(this->vecDim,DistanceTestsF64::TMPA_F64_ID,mgr); 241 tmpB.create(this->vecDim,DistanceTestsF64::TMPB_F64_ID,mgr); 242 } 243 break; 244 245 case DistanceTestsF64::TEST_COSINE_DISTANCE_F64_6: 246 { 247 ref.reload(DistanceTestsF64::REF6_F64_ID,mgr); 248 } 249 break; 250 251 case DistanceTestsF64::TEST_EUCLIDEAN_DISTANCE_F64_7: 252 { 253 ref.reload(DistanceTestsF64::REF7_F64_ID,mgr); 254 } 255 break; 256 257 case DistanceTestsF64::TEST_JENSENSHANNON_DISTANCE_F64_8: 258 { 259 inputA.reload(DistanceTestsF64::INPUTA_JEN_F64_ID,mgr); 260 inputB.reload(DistanceTestsF64::INPUTB_JEN_F64_ID,mgr); 261 dims.reload(DistanceTestsF64::DIMS_S16_ID,mgr); 262 263 const int16_t *dimsp = dims.ptr(); 264 265 this->nbPatterns=dimsp[0]; 266 this->vecDim=dimsp[1]; 267 output.create(this->nbPatterns,DistanceTestsF64::OUT_F64_ID,mgr); 268 269 ref.reload(DistanceTestsF64::REF8_F64_ID,mgr); 270 } 271 break; 272 273 case DistanceTestsF64::TEST_MINKOWSKI_DISTANCE_F64_9: 274 { 275 inputA.reload(DistanceTestsF64::INPUTA_F64_ID,mgr); 276 inputB.reload(DistanceTestsF64::INPUTB_F64_ID,mgr); 277 dims.reload(DistanceTestsF64::DIMS_MINKOWSKI_S16_ID,mgr); 278 279 const int16_t *dimsp = dims.ptr(); 280 281 this->nbPatterns=dimsp[0]; 282 this->vecDim=dimsp[1]; 283 output.create(this->nbPatterns,DistanceTestsF64::OUT_F64_ID,mgr); 284 285 ref.reload(DistanceTestsF64::REF9_F64_ID,mgr); 286 } 287 break; 288 289 } 290 291 292 293 294 295 } 296 tearDown(Testing::testID_t id,Client::PatternMgr * mgr)297 void DistanceTestsF64::tearDown(Testing::testID_t id,Client::PatternMgr *mgr) 298 { 299 (void)id; 300 output.dump(mgr); 301 } 302