Update error statistics given vectors with the before/after result of quantization
| 85 | |
| 86 | // Update error statistics given vectors with the before/after result of quantization |
| 87 | static void update_error_stats(int64_t nelements, const float * input, const float * output, error_stats & stats) { |
| 88 | for (int64_t i = 0; i < nelements; i++) { |
| 89 | double diff = input[i] - output[i]; |
| 90 | stats.total_error += diff * diff; |
| 91 | stats.max_error = fmax(fabs(diff), stats.max_error); |
| 92 | stats.error_histogram[std::max(std::min((size_t) floor(fabs(diff) / HISTOGRAM_RANGE * HISTOGRAM_BUCKETS), HISTOGRAM_BUCKETS-1), (size_t) 0)]++; |
| 93 | } |
| 94 | stats.num_samples += nelements; |
| 95 | } |
| 96 | |
| 97 | static void combine_error_stats(error_stats & into, const error_stats & from) { |
| 98 | into.num_samples += from.num_samples; |