class TestGpuGridGaussianCompute_64x32(TestCase):
    def setUp(self):
        self.size = getDimensions(self)
        a = np.array([[0, 0], [1, 1], [0, 1], [1, 0], [.5, .5]]).astype(np.float32).reshape(5, 2)
        self.sigma = .1

        test_set = CellTypeDataSet("", a, rgb=(0, .5, .5))

        # These are the individual tiles that will have information about the dataset
        test_tile = ViewTile((test_set,), (0, 1, 0, 1))

        self.new = GpuGridGaussian(test_tile, self.size, self.sigma)
        self.new.compute_grid()

    def doCleanups(self):
        self.new.clean_cuda()

    def test_shape(self):
        new_data = self.new.get_grid_data()
        assert new_data.shape == self.size

    def test_max_point_value(self):
        g = gaussian_normal_sigma(self.sigma)
        new_data = self.new.get_grid_data()
        diff = math.fabs(new_data.max() - g)
        assert diff < .00001

    def test_min_point_value(self):
        new_data = self.new.get_grid_data()
        assert new_data.min() < .001
class TestGpuGridGaussianStudyWindowSize(TestCase):
    def setUp(self):
        a = np.array([[750, 5], [0, 0], [1500, 0], [1500, 10], [0, 10], [237, 2], [237, 2], [1234, 7], [400, 3]]).astype(np.float32).reshape(9, 2)
        self.grid_size = (1024, 1024)
        self.sigma = .1

        test_set = CellTypeDataSet("", a, rgb=(0, .5, .5))

        # These are the individual tiles that will have information about the dataset
        test_tile = ViewTile((test_set,), (0, 1500, 0, 10))

        self.new = GpuGridGaussian(test_tile, self.grid_size, self.sigma)
        self.new.compute_grid()

    def doCleanups(self):
        self.new.clean_cuda()

    def test_shape(self):
        new_data = self.new.get_grid_data()
        assert new_data.shape == self.grid_size

    def test_max_point_value(self):
        g = gaussian_normal_sigma(self.sigma) * 2.425
        new_data = self.new.get_grid_data()
        diff = math.fabs(new_data.max() - g)
        print diff
        assert diff < .1

    def test_min_point_value(self):
        new_data = self.new.get_grid_data()
        assert new_data.min() < .001
class TestRandomGpuGridGaussianComputeComplex_1024x1024(TestCase):
    def setUp(self):
        self.grid_size = getDimensions(self)

        a = np.array(np.random.random(400)).astype(np.float32).reshape(200, 2)
        self.sigma = .1

        test_set = CellTypeDataSet("", a, rgb=(0, .5, .5))

        # These are the individual tiles that will have information about the dataset
        test_tile = ViewTile((test_set,), (0, 1, 0, 1))

        self.new = GpuGridGaussian(test_tile, self.grid_size, self.sigma)
        self.new.compute_grid()

    def doCleanups(self):
        self.new.clean_cuda()

    def test_shape(self):
        new_data = self.new.get_grid_data()
        assert new_data.shape == self.grid_size

    def test_max_greater_than(self):
        new_data = self.new.get_grid_data()
        assert new_data.max() > gaussian_normal_sigma(self.sigma)

    def test_min_greater_than(self):
        new_data = self.new.get_grid_data()
        assert new_data.min() > gaussian_normal_sigma(self.sigma)
class TestGpuGridGaussianCompute_32x32(TestCase):
    def setUp(self):
        self.size = getDimensions(self)
        a = np.array([[0, 0], [1, 1], [0, 1], [1, 0], [.5, .5]]).astype(np.float32).reshape(5, 2)
        sigma = .1
        test_set = CellTypeDataSet("", a, rgb=(0, .5, .5))
        test_tile = ViewTile((test_set,), (0, 1, 0, 1))
        self.new = GpuGridGaussian(test_tile, self.size, sigma)
        self.new.compute_grid()
        self.old = GpuGaussianOld(a, (0, 1, 0, 1), self.size, sigma)
        self.old.compute_grid()

    def doCleanups(self):
        self.new.clean_cuda()
        self.old.clean_cuda()

    def test_equiv_arrays(self):
        new_data = self.new.get_grid_data()
        old_data = self.old.get_grid_data()
        assert np.array_equiv(new_data, old_data)

    def test_equal_arrays(self):
        new_data = self.new.get_grid_data()
        old_data = self.old.get_grid_data()
        assert np.array_equal(new_data, old_data)

    def test_size(self):
        new_data = self.new.get_grid_data()
        assert new_data.shape == self.size
class TestGpuGridGaussianCompute_2x2(TestCase):
    def setUp(self):
        self.size = getDimensions(self)
        a = np.array([[0, 0], [1, 1], [0, 1], [1, 0], [.5, .5]]).astype(np.float32).reshape(5, 2)
        sigma = .1

        test_set = CellTypeDataSet("", a, rgb=(0, .5, .5))

        # These are the individual tiles that will have information about the dataset
        test_tile = ViewTile((test_set,), (0, 1, 0, 1))

        self.new = GpuGridGaussian(test_tile, self.size, sigma)
        self.new.compute_grid()
        self.old = GpuGaussianOld(test_tile.get_Data()[0].getDataSet(), test_tile.get_View().view(), self.size, sigma)
        self.old.compute_grid()

    def doCleanups(self):
        self.new.clean_cuda()
        self.old.clean_cuda()

    def test_equiv_arrays(self):
        new_data = self.new.get_grid_data()
        old_data = self.old.get_grid_data()
        assert np.array_equiv(new_data, old_data)

    def test_equal_arrays(self):
        new_data = self.new.get_grid_data()
        old_data = self.old.get_grid_data()
        assert np.array_equal(new_data, old_data)

    def test_size(self):
        new_data = self.new.get_grid_data()
        assert new_data.shape == self.size
        old_data = self.old.get_grid_data()
        assert old_data.shape == self.size
class TestGpuGridGaussianNoCompute(TestCase):
    def setUp(self):
        a = np.array([[0, 0], [1, 1], [0, 1], [1, 0], [.5, .5]]).astype(np.float32).reshape(5, 2)

        test_set = CellTypeDataSet("", a, rgb=(0, .5, .5))

        # These are the individual tiles that will have information about the dataset
        test_tile = ViewTile((test_set,), (0, 1, 0, 1))

        self.g = GpuGridGaussian(test_tile, (32, 32), .1)

    def doCleanups(self):
        self.g.clean_cuda()

    def test_array_equiv(self):
        image = self.g.get_grid_data()
        compare = np.zeros_like(image)
        assert np.array_equiv(image, compare)

    def test_array_equal(self):
        image = self.g.get_grid_data()
        compare = np.zeros_like(image)
        assert np.array_equal(image, compare)