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

Calls 2

strMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected