MCPcopy Create free account
hub / github.com/AnswerDotAI/gpu.cpp / isclose

Function isclose

utils/array_utils.hpp:315–323  ·  view source on GitHub ↗

* @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. */

Source from the content-addressed store, hash-verified

313 * @return bool True if the arrays are close, false otherwise.
314 */
315inline 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
325inline bool isclose(half *a, half *b, size_t n, float tol = 1) {
326 for (size_t i = 0; i < n; i++) {

Callers 7

checkCPUFunction · 0.85
mainFunction · 0.85
testResidualFunction · 0.85
testMatmulFunction · 0.85
testGeluFunction · 0.85
testLayerNormFunction · 0.85
testSoftmaxFunction · 0.85

Calls 2

LOGFunction · 0.85
halfToFloatFunction · 0.85

Tested by 5

testResidualFunction · 0.68
testMatmulFunction · 0.68
testGeluFunction · 0.68
testLayerNormFunction · 0.68
testSoftmaxFunction · 0.68