* @brief Determine if the values of two arrays are close to each other. * @param a The first array. * @param b The second array. * @param n The number of elements in the arrays. * @param tol The tolerance for closeness. * @return bool True if the arrays are close, false otherwise. */
| 313 | * @return bool True if the arrays are close, false otherwise. |
| 314 | */ |
| 315 | inline bool isclose(float *a, float *b, size_t n, float tol = 1e-3) { |
| 316 | for (size_t i = 0; i < n; i++) { |
| 317 | if (std::abs(a[i] - b[i]) > tol || std::isnan(a[i]) || std::isnan(b[i])) { |
| 318 | LOG(kDefLog, kError, "Mismatch at index %d: %f != %f", i, a[i], b[i]); |
| 319 | return false; |
| 320 | } |
| 321 | } |
| 322 | return true; |
| 323 | } |
| 324 | |
| 325 | inline bool isclose(half *a, half *b, size_t n, float tol = 1) { |
| 326 | for (size_t i = 0; i < n; i++) { |