MCPcopy Create free account
hub / github.com/alibaba/MNN / computeDistance

Method computeDistance

tools/quantization/TensorStatistic.cpp:307–326  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

305}
306
307float 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}

Callers 1

_computeQuantErrorMethod · 0.80

Calls 2

sqrtFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected