def test_copy_dtypes_for_restore(): # TODO using dtype=np.bool is causing this to fail as it ends up being <type bool> instead of # <type 'numpy.bool_'>. Any problems from that for the library? images = [ np.zeros((1, 1, 3), dtype=np.uint8), np.zeros((10, 16, 3), dtype=np.float32), np.zeros((20, 10, 6), dtype=np.int32) ] dtypes_copy = iadt.copy_dtypes_for_restore(images, force_list=False) assert all([ dtype_i.type == dtype_j for dtype_i, dtype_j in zip( dtypes_copy, [np.uint8, np.float32, np.int32]) ]) dts = [np.uint8, np.float32, np.int32] for dt in dts: images = np.zeros((10, 16, 32, 3), dtype=dt) dtypes_copy = iadt.copy_dtypes_for_restore(images) assert isinstance(dtypes_copy, np.dtype) assert dtypes_copy.type == dt dtypes_copy = iadt.copy_dtypes_for_restore(images, force_list=True) assert isinstance(dtypes_copy, list) assert all([dtype_i.type == dt for dtype_i in dtypes_copy])
def test_images_as_single_array(self): dts = ["uint8", "float32", "int32"] for dt in dts: with self.subTest(dtype=dt): images = np.zeros((10, 16, 32, 3), dtype=dt) dtypes_copy = iadt.copy_dtypes_for_restore(images) assert isinstance(dtypes_copy, np.dtype) assert dtypes_copy.name == dt
def test_images_as_single_array_force_list(self): dts = ["uint8", "float32", "int32"] for dt in dts: with self.subTest(dtype=dt): images = np.zeros((10, 16, 32, 3), dtype=dt) dtypes_copy = iadt.copy_dtypes_for_restore(images, force_list=True) assert isinstance(dtypes_copy, list) assert np.all([dtype_i.name == dt for dtype_i in dtypes_copy])
def test_copy_dtypes_for_restore(): # TODO using dtype=np.bool is causing this to fail as it ends up being <type bool> instead of # <type 'numpy.bool_'>. Any problems from that for the library? images = [ np.zeros((1, 1, 3), dtype=np.uint8), np.zeros((10, 16, 3), dtype=np.float32), np.zeros((20, 10, 6), dtype=np.int32) ] dtypes_copy = iadt.copy_dtypes_for_restore(images, force_list=False) assert all([dtype_i.type == dtype_j for dtype_i, dtype_j in zip(dtypes_copy, [np.uint8, np.float32, np.int32])]) dts = [np.uint8, np.float32, np.int32] for dt in dts: images = np.zeros((10, 16, 32, 3), dtype=dt) dtypes_copy = iadt.copy_dtypes_for_restore(images) assert isinstance(dtypes_copy, np.dtype) assert dtypes_copy.type == dt dtypes_copy = iadt.copy_dtypes_for_restore(images, force_list=True) assert isinstance(dtypes_copy, list) assert all([dtype_i.type == dt for dtype_i in dtypes_copy])
def test_images_as_list(self): # TODO using dtype=np.bool is causing this to fail as it ends up # being <type bool> instead of <type 'numpy.bool_'>. # Any problems from that for the library? images = [ np.zeros((1, 1, 3), dtype=np.uint8), np.zeros((10, 16, 3), dtype=np.float32), np.zeros((20, 10, 6), dtype=np.int32) ] dtypes_copy = iadt.copy_dtypes_for_restore(images, force_list=False) assert np.all([ dtype_observed.name == dtype_expected for dtype_observed, dtype_expected in zip(dtypes_copy, ["uint8", "float32", "int32"]) ])