def test_numpy_share_memory(self): # TODO: do pytest parametarize once we move to pytest np_img = np.arange(4 * 5 * 3, dtype=np.uint8).reshape(4, 5, 3) vital_img = Image(np_img) assert np.all( np_img == vital_img.asarray()), ('must be initially the same') np_img += 1 assert np.all( np_img != vital_img.asarray()), ('we do not share memory yet')
def _test_numpy(dtype_name, nchannels, order='c'): np_img = create_numpy_image(dtype_name, nchannels, order) vital_img = Image(np_img) recast = vital_img.asarray() # asarray always returns 3 channels np_img = np.atleast_3d(np_img) pixel_type_name = vital_img.pixel_type_name() want = map_dtype_name_to_pixel_type(dtype_name) assert pixel_type_name == want, 'want={} but got={}'.format( want, pixel_type_name) if not np.all(np_img == recast): raise AssertionError( 'Failed dtype={}, nchannels={}, order={}'.format( dtype_name, nchannels, order))