MCPcopy Create free account
hub / github.com/ComputationalRobotics/XM-code / save_matrix_to_bin

Function save_matrix_to_bin

utils/io.py:17–33  ·  view source on GitHub ↗
(filename, matrix, byte = 4)

Source from the content-addressed store, hash-verified

15 f.flush()
16
17def save_matrix_to_bin(filename, matrix, byte = 4):
18 try:
19 with open(filename, "wb") as file:
20 rows, cols = matrix.shape
21 # default is 4-bit int
22 if byte == 4:
23 file.write(rows.to_bytes(4, byteorder='little'))
24 file.write(cols.to_bytes(4, byteorder='little'))
25 elif byte == 8:
26 file.write(rows.to_bytes(8, byteorder='little', signed=False))
27 file.write(cols.to_bytes(8, byteorder='little', signed=False))
28
29 matrix.T.tofile(file)
30
31 print(f"Matrix saved to {filename}. Rows: {rows}, Cols: {cols}")
32 except IOError:
33 print("Cannot write to file")
34
35def load_matrix_from_bin(filename, byte = 4):
36 try:

Callers 1

create_matrixFunction · 0.90

Calls 1

writeMethod · 0.80

Tested by

no test coverage detected