def test_fail_with_normal_array_return_to_second(self): """ This test does not use shared arrays and will not change the data. This behaviour is intended and is """ # create data as normal nd array img = th.gen_img_numpy_rand() img2nd = th.gen_img_numpy_rand() # get the expected as usual expected = img + img2nd # make sure it hasnt changed the original array assert expected[0, 0, 0] != img[0, 0, 0] assert expected[1, 0, 0] != img[1, 0, 0] assert expected[0, 4, 0] != img[0, 4, 0] assert expected[6, 0, 1] != img[6, 0, 1] # create partial f = ptsm.create_partial(return_from_func, fwd_function=ptsm.return_to_second, add_arg=5) # execute parallel res1, res2 = ptsm.execute(img, img2nd, f) # compare results npt.assert_equal(res1, img) npt.assert_equal(res2, img2nd) th.assert_not_equals(res2, expected)
def test_fail_with_normal_array_return_to_first(self): # create data as normal nd array img = th.gen_img_numpy_rand() img2nd = th.gen_img_numpy_rand() # get the expected as usual expected = img + img2nd # make sure it hasnt changed the original array assert expected[0, 0, 0] != img[0, 0, 0] assert expected[1, 0, 0] != img[1, 0, 0] assert expected[0, 4, 0] != img[0, 4, 0] assert expected[6, 0, 1] != img[6, 0, 1] # create partial f = ptsm.create_partial(return_from_func, fwd_function=ptsm.return_to_first, add_arg=5) # execute parallel res1, res2 = ptsm.execute(img, img2nd, f) # compare results npt.assert_equal(res1, img) npt.assert_equal(res2, img2nd) th.assert_not_equals(res1, expected)
def test_fail_with_normal_array_fwd_func_second_2d(self): # shape of 11 forces the execution to be parallel img = th.gen_img_numpy_rand((11, 10, 10)) orig_img = np.copy(img) img2nd = th.gen_img_numpy_rand((11, 10, 10)) orig_img2nd = np.copy(img2nd) img2nd = img2nd[0] # get the expected as usual expected = img + img2nd # make sure it hasnt changed the original array assert expected[0, 0, 0] != img[0, 0, 0] assert expected[1, 0, 0] != img[1, 0, 0] assert expected[0, 4, 0] != img[0, 4, 0] assert expected[6, 0, 1] != img[6, 0, 1] # create partial f = ptsm.create_partial(add_inplace, fwd_function=ptsm.inplace_second_2d, add_arg=5) # execute parallel ptsm.execute(img, img2nd, f) # compare results th.assert_not_equals(img, expected) th.assert_not_equals(img2nd, expected) npt.assert_equal(img, orig_img) npt.assert_equal(img2nd, orig_img2nd[0])
def test_metadata_round_trip(self): # Create dummy image stack sample = th.gen_img_numpy_rand() images = Images(sample) images.metadata['message'] = 'hello, world!' # Save image stack saver.save(images, self.output_directory) # Load image stack back dataset = loader.load(self.output_directory) loaded_images = dataset.sample # Ensure properties have been preserved self.assertEqual(loaded_images.metadata, images.metadata)
def test_fail_with_normal_array_fwd_func(self): # create data as shared array img = th.gen_img_numpy_rand((11, 10, 10)) orig = np.copy(img) add_arg = 5 expected = img + add_arg assert expected[0, 0, 0] != img[0, 0, 0] assert expected[1, 0, 0] != img[1, 0, 0] assert expected[0, 4, 0] != img[0, 4, 0] assert expected[6, 0, 1] != img[6, 0, 1] # create partial f = psm.create_partial(return_from_func, fwd_func=psm.return_fwd_func, add_arg=add_arg) # execute parallel res = psm.execute(img, f) # compare results th.assert_not_equals(res, expected) npt.assert_equal(img, orig)