(filename, byte = 4)
| 33 | print("Cannot write to file") |
| 34 | |
| 35 | def load_matrix_from_bin(filename, byte = 4): |
| 36 | try: |
| 37 | with open(filename, "rb") as file: |
| 38 | if byte == 4: |
| 39 | rows = int.from_bytes(file.read(4), byteorder='little') |
| 40 | cols = int.from_bytes(file.read(4), byteorder='little') |
| 41 | elif byte == 8: |
| 42 | rows = int.from_bytes(file.read(8), byteorder='little', signed=False) |
| 43 | cols = int.from_bytes(file.read(8), byteorder='little', signed=False) |
| 44 | |
| 45 | n = rows |
| 46 | |
| 47 | matrix = np.fromfile(file, dtype=np.double, count=rows * cols) |
| 48 | matrix = matrix.reshape((rows, cols), order='F') |
| 49 | |
| 50 | print(f"rows: {rows}, cols: {cols}") |
| 51 | return matrix, n |
| 52 | except IOError: |
| 53 | print("Cannot open file") |
| 54 | return None, None |
| 55 | |
| 56 | def save_array_to_bin(filename, array): |
| 57 | """ |
no outgoing calls
no test coverage detected