| 23 | }; |
| 24 | |
| 25 | static 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. |
no test coverage detected