| 26 | // load .*vecs file to a matrix (e.g., RowMajorFloatMat) |
| 27 | template <typename T, class M> |
| 28 | void 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) |
| 59 | template <typename T, class M> |
nothing calls this directly
no test coverage detected