| 24 | |
| 25 | void require(bool condition, const std::string & message) { |
| 26 | if (!condition) { |
| 27 | throw std::runtime_error(message); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | void 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 | } |
no test coverage detected