| 277 | } |
| 278 | |
| 279 | std::pair<std::vector<float>, float> TensorStatistic::fakeQuantFeature() { |
| 280 | const int count = mOriginTensor->elementSize(); |
| 281 | const float bound = mFeatureClampValue; |
| 282 | float* originData = mOriginTensor->host<float>(); |
| 283 | const float scale = mScale; |
| 284 | std::vector<float> fakeQuantedFeature; |
| 285 | int overflowCount = 0; |
| 286 | |
| 287 | for (int i = 0; i < count; i++) { |
| 288 | float dataQuant = std::roundf(originData[i] / scale) + mZeroPoint; |
| 289 | dataQuant = std::fmin(bound, std::fmax(-bound, dataQuant)); |
| 290 | float dataDequant = (dataQuant - mZeroPoint) * scale; |
| 291 | |
| 292 | originData[i] = dataDequant; |
| 293 | fakeQuantedFeature.emplace_back(dataDequant); |
| 294 | |
| 295 | if (std::fabs(std::fabs(dataQuant) - bound) < 1e-6) { |
| 296 | overflowCount++; |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | float overflowRatio = overflowCount / float(count); |
| 301 | auto result = std::make_pair(fakeQuantedFeature, overflowRatio); |
| 302 | |
| 303 | mVisited = true; |
| 304 | return result; |
| 305 | } |
| 306 | |
| 307 | float TensorStatistic::computeDistance(std::vector<float> fakeQuantedFeature) { |
| 308 | const int count = mOriginTensor->elementSize(); |
no test coverage detected