Exemplo n.º 1
0
    def test_fwd_func_second_2d(self):
        # create data as shared array
        img = th.generate_shared_array()
        img2nd, orig_2nd = th.generate_shared_array_and_copy()

        img2nd = img2nd[0]

        # make sure it hasnt changed the original array
        expected = img + img2nd + 5
        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
        npt.assert_equal(img, expected)
        npt.assert_equal(img2nd, orig_2nd[0])
Exemplo n.º 2
0
    def test_memory_return_to_second(self):
        # create data as shared array
        img, orig_img = th.generate_shared_array_and_copy()
        img2nd = th.generate_shared_array()

        # make sure it hasnt changed the original array
        expected = img + img2nd + 5
        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
        cached_memory = get_memory_usage_linux(kb=True)[0]
        res1, res2 = ptsm.execute(img, img2nd, f)
        self.assertLess(
            get_memory_usage_linux(kb=True)[0], cached_memory * 1.1)
        # compare results
        npt.assert_equal(res2, expected)
        npt.assert_equal(res1, orig_img)
Exemplo n.º 3
0
    def test_memory_fwd_func_inplace(self):
        # create data as shared array
        img = th.generate_shared_array()
        img2nd, orig_2nd = th.generate_shared_array_and_copy()

        # make sure it hasnt changed the original array
        expected = img + img2nd + 5
        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,
                                add_arg=5)

        cached_memory = get_memory_usage_linux(kb=True)[0]
        # execute parallel
        ptsm.execute(img, img2nd, f)
        self.assertLess(
            get_memory_usage_linux(kb=True)[0], cached_memory * 1.1)
        # compare results
        npt.assert_equal(img, expected)
        npt.assert_equal(img2nd, orig_2nd)
Exemplo n.º 4
0
    def test_memory_fwd_func(self):
        """
        Expected behaviour for the filter is to be done in place
        without using more memory.
        In reality the memory is increased by about 40MB (4 April 2017),
        but this could change in the future.
        The reason why a 10% window is given on the expected size is
        to account for any library imports that may happen.
        This will still capture if the data is doubled, which is the main goal.
        """
        # create data as shared array
        img, _ = th.generate_shared_array_and_copy()
        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)

        cached_memory = get_memory_usage_linux(kb=True)[0]
        # execute parallel
        img = psm.execute(img, f)
        self.assertLess(
            get_memory_usage_linux(kb=True)[0], cached_memory * 1.1)

        # compare results
        npt.assert_equal(img, expected)
Exemplo n.º 5
0
    def test_memory_fwd_func_inplace(self):
        # create data as shared array
        img, _ = th.generate_shared_array_and_copy()
        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(add_inplace,
                               fwd_func=psm.inplace,
                               add_arg=add_arg)

        cached_memory = get_memory_usage_linux(kb=True)[0]
        # execute parallel
        img = psm.execute(img, f)

        self.assertLess(
            get_memory_usage_linux(kb=True)[0], cached_memory * 1.1)

        # compare results
        npt.assert_equal(img, expected)
Exemplo n.º 6
0
    def test_fwd_func(self):
        # create data as shared array
        img, _ = th.generate_shared_array_and_copy()
        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
        img = psm.execute(img, f)

        # compare results
        npt.assert_equal(img, expected)
Exemplo n.º 7
0
    def test_return_to_first(self):
        # create data as shared array
        img = th.generate_shared_array()
        img2nd, orig_2nd = th.generate_shared_array_and_copy()

        # make sure it hasnt changed the original array
        expected = img + img2nd + 5
        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, expected)
        npt.assert_equal(res2, orig_2nd)