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

Function require_allclose

tests/unittests/test_encoder_modules.cpp:26–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24
25void require(bool condition, const std::string & message) {
26 if (!condition) {
27 throw std::runtime_error(message);
28 }
29}
30
31void require_allclose(
32 const std::vector<float> & actual,
33 const std::vector<float> & expected,
34 float atol,
35 const std::string & label) {
36 if (actual.size() != expected.size()) {
37 throw std::runtime_error(label + " size mismatch");
38 }
39 for (size_t i = 0; i < actual.size(); ++i) {
40 const float diff = std::fabs(actual[i] - expected[i]);
41 if (!std::isfinite(diff) || diff > atol) {
42 std::ostringstream oss;
43 oss << label << " mismatch at " << i << ": expected " << expected[i] << ", got " << actual[i]
44 << ", diff=" << diff;
45 throw std::runtime_error(oss.str());
46 }

Calls 2

strMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected