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

Function compare_ggml_vs_nchw

tests/test_debug_encoder.cpp:34–52  ·  view source on GitHub ↗

Compare C++ ggml tensor (dumped as [C, W, H]) vs Python NCHW [1, C, H, W] ggml stores: flat[c + w*C + h*C*W] Python NCHW: flat[c*H*W + h*W + w] These differ! Need transposition.

Source from the content-addressed store, hash-verified

32// Python NCHW: flat[c*H*W + h*W + w]
33// These differ! Need transposition.
34static compare_result compare_ggml_vs_nchw(const ref_tensor_f32& cpp,
35 const ref_tensor_f32& ref) {
36 if (cpp.shape.size() < 3 || ref.data.empty()) {
37 compare_result r;
38 r.max_diff = 999.0f;
39 return r;
40 }
41 int C = cpp.shape[0], W = cpp.shape[1], H = cpp.shape[2];
42
43 // Transpose ggml → NCHW
44 std::vector<float> transposed(C * W * H);
45 for (int c = 0; c < C; ++c)
46 for (int h = 0; h < H; ++h)
47 for (int w = 0; w < W; ++w)
48 transposed[c * H * W + h * W + w] = cpp.data[c + w * C + h * C * W];
49
50 return compare_tensors(transposed.data(), ref.data.data(),
51 std::min((int)transposed.size(), ref.numel()));
52}
53
54static void print_result(const char* name, const compare_result& r, float atol) {
55 const char* status = (r.max_diff < atol) ? "[PASS]" : "[FAIL]";

Callers 1

mainFunction · 0.70

Calls 2

compare_tensorsFunction · 0.70
numelMethod · 0.45

Tested by

no test coverage detected