MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / update_error_stats

Function update_error_stats

examples/quantize-stats/quantize-stats.cpp:87–95  ·  view source on GitHub ↗

Update error statistics given vectors with the before/after result of quantization

Source from the content-addressed store, hash-verified

85
86// Update error statistics given vectors with the before/after result of quantization
87static 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
97static void combine_error_stats(error_stats & into, const error_stats & from) {
98 into.num_samples += from.num_samples;

Callers 1

test_roundtrip_on_chunkFunction · 0.70

Calls 2

maxFunction · 0.85
minFunction · 0.85

Tested by 1

test_roundtrip_on_chunkFunction · 0.56