def test_matrix_mm_read_write(tmp_path): mmf = tmp_path / 'mmwrite_test.mm' mmf.touch() m = Matrix.from_lists([0, 1, 2], [0, 1, 2], [2, 3, 4]) with mmf.open('w') as f: m.to_mm(f) with mmf.open() as f: assert f.readlines() == [ '%%MatrixMarket matrix coordinate integer symmetric\n', '%%GraphBLAS GrB_INT64\n', '3 3 3\n', '1 1 2\n', '2 2 3\n', '3 3 4\n' ] with mmf.open() as f: n = Matrix.from_mm(f) assert n == m
def from_mm_file(path): with open(path, 'r') as f: graph = WeightedGraph() graph.matrix = Matrix.from_mm(f, FP64) return graph