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

Function compute_metrics

tests/test_metal_python_ref_compare.cpp:41–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39}
40
41static metric_row compute_metrics(const std::string & tensor,
42 const float * got,
43 const float * ref,
44 int n,
45 const std::vector<int> & ref_shape) {
46 metric_row row;
47 row.tensor = tensor;
48 row.shape = shape_to_string(ref_shape);
49 if (n <= 0) {
50 row.note = "empty";
51 return row;
52 }
53
54 double sum_abs = 0.0;
55 double sum_rel = 0.0;
56 double dot_ab = 0.0;
57 double dot_aa = 0.0;
58 double dot_bb = 0.0;
59 float max_abs = 0.0f;
60
61 for (int i = 0; i < n; ++i) {
62 const float a = got[i];
63 const float b = ref[i];
64 const float d = fabsf(a - b);
65 sum_abs += d;
66 sum_rel += d / (fabsf(b) + 1e-8f);
67 if (d > max_abs) {
68 max_abs = d;
69 }
70 dot_ab += (double) a * (double) b;
71 dot_aa += (double) a * (double) a;
72 dot_bb += (double) b * (double) b;
73 }
74
75 row.max_abs = max_abs;
76 row.mean_abs = (float) (sum_abs / n);
77 row.mean_rel = (float) (sum_rel / n);
78 const double denom = sqrt(dot_aa) * sqrt(dot_bb);
79 row.cosine = denom > 0.0 ? (float) (dot_ab / denom) : 0.0f;
80 row.measured = true;
81 return row;
82}
83
84static std::vector<float> ggml_dump_to_nhwc_flat(const ref_tensor_f32 & cpp) {
85 std::vector<float> out;

Callers 3

compare_state_nhwcFunction · 0.85
compare_state_nchwFunction · 0.85
compare_dump_directFunction · 0.85

Calls 1

shape_to_stringFunction · 0.85

Tested by

no test coverage detected