MCPcopy Create free account
hub / github.com/VectorDB-NTU/RaBitQ-Library / load_bin

Function load_bin

include/rabitqlib/utils/io.hpp:60–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58// load .*bin file to a matrix (e.g., RowMajorFloatMat)
59template <typename T, class M>
60void load_bin(const char* filename, M& row_mat) {
61 if (!file_exists(filename)) {
62 std::cerr << "File " << filename << " not exists\n";
63 exit(1);
64 }
65
66 assert((std::is_same_v<T*, std::decay_t<decltype(row_mat.data())>> == true));
67
68 uint32_t rows;
69 uint32_t cols;
70 std::ifstream input(filename, std::ios::binary);
71
72 input.read(reinterpret_cast<char*>(&rows), sizeof(uint32_t));
73 input.read(reinterpret_cast<char*>(&cols), sizeof(uint32_t));
74
75 row_mat = M(rows, cols);
76
77 for (size_t i = 0; i < rows; i++) {
78 input.read(reinterpret_cast<char*>(&row_mat(i, 0)), sizeof(T) * cols);
79 }
80
81 std::cout << "File " << filename << " loaded\n";
82 std::cout << "Rows " << rows << " Cols " << cols << '\n' << std::flush;
83 input.close();
84}
85} // namespace rabitqlib

Callers

nothing calls this directly

Calls 2

file_existsFunction · 0.85
dataMethod · 0.45

Tested by

no test coverage detected