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

Function load_vecs

include/rabitqlib/utils/io.hpp:28–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26// load .*vecs file to a matrix (e.g., RowMajorFloatMat)
27template <typename T, class M>
28void load_vecs(const char* filename, M& row_mat) {
29 if (!file_exists(filename)) {
30 std::cerr << "File " << filename << " not exists\n";
31 exit(1);
32 }
33
34 assert((std::is_same_v<T*, std::decay_t<decltype(row_mat.data())>> == true));
35
36 uint32_t tmp;
37 size_t file_size = get_filesize(filename);
38 std::ifstream input(filename, std::ios::binary);
39
40 input.read(reinterpret_cast<char*>(&tmp), sizeof(uint32_t));
41
42 size_t cols = tmp;
43 size_t rows = file_size / (cols * sizeof(T) + sizeof(uint32_t));
44 row_mat = M(rows, cols);
45
46 input.seekg(0, std::ifstream::beg);
47
48 for (size_t i = 0; i < rows; i++) {
49 input.read(reinterpret_cast<char*>(&tmp), sizeof(uint32_t));
50 input.read(reinterpret_cast<char*>(&row_mat(i, 0)), sizeof(T) * cols);
51 }
52
53 std::cout << "File " << filename << " loaded\n";
54 std::cout << "Rows " << rows << " Cols " << cols << '\n' << std::flush;
55 input.close();
56}
57
58// load .*bin file to a matrix (e.g., RowMajorFloatMat)
59template <typename T, class M>

Callers

nothing calls this directly

Calls 3

file_existsFunction · 0.85
get_filesizeFunction · 0.85
dataMethod · 0.45

Tested by

no test coverage detected