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

Function load_ref

tests/test_vit.cpp:25–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23};
24
25static ref_tensor load_ref(const std::string & path) {
26 ref_tensor t;
27 // Load shape
28 {
29 std::ifstream f(path + ".shape");
30 if (!f) {
31 fprintf(stderr, " [SKIP] %s.shape not found\n", path.c_str());
32 return t;
33 }
34 std::string line;
35 std::getline(f, line);
36 size_t pos = 0;
37 while (pos < line.size()) {
38 size_t end = line.find(',', pos);
39 if (end == std::string::npos) end = line.size();
40 t.shape.push_back(std::stoi(line.substr(pos, end - pos)));
41 pos = end + 1;
42 }
43 }
44 // Load data
45 {
46 std::ifstream f(path + ".bin", std::ios::binary);
47 if (!f) {
48 fprintf(stderr, " [SKIP] %s.bin not found\n", path.c_str());
49 t.shape.clear();
50 return t;
51 }
52 t.data.resize(t.numel());
53 f.read(reinterpret_cast<char *>(t.data.data()), t.numel() * sizeof(float));
54 }
55 return t;
56}
57
58// Compare two float arrays with tolerance.
59// Returns max absolute difference.

Callers 4

test_preprocessingFunction · 0.70
test_ropeFunction · 0.70
test_sinusoidal_peFunction · 0.70
test_encode_imageFunction · 0.70

Calls 1

numelMethod · 0.45

Tested by

no test coverage detected