MCPcopy Create free account
hub / github.com/PABannier/sam3.cpp / compare_tensors

Function compare_tensors

tests/test_phase3.cpp:77–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75};
76
77static compare_result compare_tensors(const float * a, const float * b, int n,
78 float atol = 1e-4f) {
79 compare_result r;
80 r.n_elements = n;
81 double sum_diff = 0.0;
82 double dot_ab = 0.0, dot_aa = 0.0, dot_bb = 0.0;
83 for (int i = 0; i < n; ++i) {
84 float diff = fabsf(a[i] - b[i]);
85 if (diff > r.max_diff) r.max_diff = diff;
86 if (diff > atol) r.n_bad++;
87 sum_diff += diff;
88 dot_ab += (double)a[i] * b[i];
89 dot_aa += (double)a[i] * a[i];
90 dot_bb += (double)b[i] * b[i];
91 }
92 r.mean_diff = (float)(sum_diff / n);
93 if (dot_aa > 0 && dot_bb > 0) {
94 r.cosine_sim = dot_ab / (sqrt(dot_aa) * sqrt(dot_bb));
95 }
96 return r;
97}
98
99static bool check(const std::string & name, const float * got, const ref_tensor & ref,
100 float atol, int & n_pass, int & n_fail) {

Callers 4

checkFunction · 0.70
test_ropeFunction · 0.70
test_encode_imageFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected