| 305 | } |
| 306 | |
| 307 | float TensorStatistic::computeDistance(std::vector<float> fakeQuantedFeature) { |
| 308 | const int count = mOriginTensor->elementSize(); |
| 309 | CHECK_EQ(count, fakeQuantedFeature.size()) << "feature size error"; |
| 310 | const float bound = mFeatureClampValue; |
| 311 | float* originData = mOriginTensor->host<float>(); |
| 312 | float axbSum = 0.0f; |
| 313 | float a2Sum = 0.0f; |
| 314 | float b2Sum = 0.0f; |
| 315 | |
| 316 | for (int i = 0; i < count; i++) { |
| 317 | axbSum += (originData[i] * fakeQuantedFeature[i]); |
| 318 | a2Sum += (originData[i] * originData[i]); |
| 319 | b2Sum += (fakeQuantedFeature[i] * fakeQuantedFeature[i]); |
| 320 | } |
| 321 | |
| 322 | float cosDis = axbSum / std::sqrt(a2Sum) / std::sqrt(b2Sum); |
| 323 | |
| 324 | mVisited = true; |
| 325 | return cosDis; |
| 326 | } |
no test coverage detected