def test_rectangles_to_numpy(self): nd = np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]) rects = [[0, 3, 0, 1], [1, 2, 0, 2]] with hl.TemporaryDirectory() as rect_uri, hl.TemporaryDirectory() as rect_bytes_uri: BlockMatrix.from_numpy(nd).export_rectangles(rect_uri, rects) BlockMatrix.from_numpy(nd).export_rectangles(rect_bytes_uri, rects, binary=True) expected = np.array([[1.0, 0.0], [4.0, 5.0], [7.0, 0.0]]) self._assert_eq(expected, BlockMatrix.rectangles_to_numpy(rect_uri)) self._assert_eq(expected, BlockMatrix.rectangles_to_numpy(rect_bytes_uri, binary=True))
def test_export_blocks(self): nd = np.ones(shape=(8, 10)) bm = BlockMatrix.from_numpy(nd, block_size=20) with hl.TemporaryDirectory() as bm_uri: bm.export_blocks(bm_uri, binary=True) actual = BlockMatrix.rectangles_to_numpy(bm_uri, binary=True) self._assert_eq(nd, actual)
def test_export_blocks(self): nd = np.ones(shape=(8, 10)) bm = BlockMatrix.from_numpy(nd, block_size=20) bm_path = new_local_temp_dir() bm_uri = local_path_uri(bm_path) bm.export_blocks(bm_uri, binary=True) actual = BlockMatrix.rectangles_to_numpy(bm_path, binary=True) self._assert_eq(nd, actual)
def test_export_blocks(self): nd = np.ones(shape=(8, 10)) bm = BlockMatrix.from_numpy(nd, block_size=20) bm_path = new_local_temp_dir() bm_uri = local_path_uri(bm_path) bm.export_blocks(bm_uri, binary=True) actual = BlockMatrix.rectangles_to_numpy(bm_path, binary=True) self._assert_eq(nd, actual)
def test_rectangles_to_numpy(self): nd = np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]) rects = [[0, 3, 0, 1], [1, 2, 0, 2]] rect_path = new_local_temp_dir() rect_uri = local_path_uri(rect_path) BlockMatrix.from_numpy(nd).export_rectangles(rect_uri, rects) rect_bytes_path = new_local_temp_dir() rect_bytes_uri = local_path_uri(rect_bytes_path) BlockMatrix.from_numpy(nd).export_rectangles(rect_bytes_uri, rects, binary=True) expected = np.array([[1.0, 0.0], [4.0, 5.0], [7.0, 0.0]]) self._assert_eq(expected, BlockMatrix.rectangles_to_numpy(rect_path)) self._assert_eq( expected, BlockMatrix.rectangles_to_numpy(rect_bytes_path, binary=True))
def test_rectangles_to_numpy(self): nd = np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]) rects = [[0, 3, 0, 1], [1, 2, 0, 2]] rect_path = new_local_temp_dir() rect_uri = local_path_uri(rect_path) BlockMatrix.from_numpy(nd).export_rectangles(rect_uri, rects) rect_bytes_path = new_local_temp_dir() rect_bytes_uri = local_path_uri(rect_bytes_path) BlockMatrix.from_numpy(nd).export_rectangles(rect_bytes_uri, rects, binary=True) expected = np.array([[1.0, 0.0], [4.0, 5.0], [7.0, 0.0]]) self._assert_eq(expected, BlockMatrix.rectangles_to_numpy(rect_path)) self._assert_eq(expected, BlockMatrix.rectangles_to_numpy(rect_bytes_path, binary=True))