MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / require_max_abs_diff_below

Function require_max_abs_diff_below

tests/unittests/test_encoder_modules.cpp:45–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43 float atol,
44 const std::string & label) {
45 if (actual.size() != expected.size()) {
46 throw std::runtime_error(label + " size mismatch");
47 }
48 for (size_t i = 0; i < actual.size(); ++i) {
49 const float diff = std::fabs(actual[i] - expected[i]);
50 if (!std::isfinite(diff) || diff > atol) {
51 std::ostringstream oss;
52 oss << label << " mismatch at " << i << ": expected " << expected[i] << ", got " << actual[i]
53 << ", diff=" << diff;
54 throw std::runtime_error(oss.str());
55 }
56 }
57}
58
59void require_max_abs_diff_below(
60 const std::vector<float> & actual,
61 const std::vector<float> & expected,
62 float max_allowed,
63 double mean_allowed,
64 const std::string & label) {
65 if (actual.size() != expected.size()) {
66 throw std::runtime_error(label + " size mismatch");
67 }
68 float max_diff = 0.0f;
69 size_t max_index = 0;
70 double mean_diff = 0.0;
71 for (size_t i = 0; i < actual.size(); ++i) {
72 const float diff = std::fabs(actual[i] - expected[i]);
73 mean_diff += diff;
74 if (diff > max_diff) {
75 max_diff = diff;
76 max_index = i;
77 }

Calls 2

strMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected