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