def test_read_tns(): with tempfile.TemporaryDirectory() as test_dir: file_name = os.path.join(test_dir, "data.tns") with open(file_name, "w") as file: file.write(_TNS_DATA) a = mlir_pytaco_io.read(file_name, _FORMAT) passed = 0 # The value of a is stored as an MLIR sparse tensor. passed += (not a.is_unpacked()) a.unpack() passed += (a.is_unpacked()) coords, values = a.get_coordinates_and_values() passed += np.array_equal(coords, [[0, 1], [2, 0], [2, 1]]) passed += np.allclose(values, [2.0, 3.0, 4.0]) # CHECK: 4 print(passed)
def test_read_mtx_matrix_symmetry(): with tempfile.TemporaryDirectory() as test_dir: file_name = os.path.join(test_dir, "data.mtx") with open(file_name, "w") as file: file.write(_get_mtx_data("symmetric")) a = mlir_pytaco_io.read(file_name, _FORMAT) passed = 0 # The value of a is stored as an MLIR sparse tensor. passed += (not a.is_unpacked()) a.unpack() passed += (a.is_unpacked()) coords, values = a.get_coordinates_and_values() print(coords) print(values) passed += np.allclose(coords, [[0, 1], [0, 2], [1, 0], [1, 2], [2, 0], [2, 1]]) passed += np.allclose(values, [2.0, 3.0, 2.0, 4.0, 3.0, 4.0]) # CHECK: 4 print(passed)