Esempio n. 1
0
def test_manhattan_distances_execution(setup, x, y, is_sparse):
    if is_sparse:
        rx, ry = raw_sparse_x, raw_sparse_y
    else:
        rx, ry = raw_x, raw_y

    sv = [True, False] if not is_sparse else [True]

    for sum_over_features in sv:
        d = manhattan_distances(x, y, sum_over_features)

        result = d.execute().fetch()
        expected = sk_manhattan_distances(rx,
                                          ry,
                                          sum_over_features=sum_over_features)

        np.testing.assert_almost_equal(result, expected)

        d = manhattan_distances(x, sum_over_features=sum_over_features)

        result = d.execute().fetch()
        expected = sk_manhattan_distances(rx,
                                          sum_over_features=sum_over_features)

        np.testing.assert_almost_equal(result, expected)
Esempio n. 2
0
    def testManhattanDistancesExecution(self):
        raw_x = np.random.rand(20, 5)
        raw_y = np.random.rand(21, 5)

        x1 = mt.tensor(raw_x, chunk_size=30)
        y1 = mt.tensor(raw_y, chunk_size=30)

        x2 = mt.tensor(raw_x, chunk_size=11)
        y2 = mt.tensor(raw_y, chunk_size=12)

        raw_sparse_x = sps.random(20,
                                  5,
                                  density=0.4,
                                  format='csr',
                                  random_state=0)
        raw_sparse_y = sps.random(21,
                                  5,
                                  density=0.3,
                                  format='csr',
                                  random_state=0)

        x3 = mt.tensor(raw_sparse_x, chunk_size=30)
        y3 = mt.tensor(raw_sparse_y, chunk_size=30)

        x4 = mt.tensor(raw_sparse_x, chunk_size=11)
        y4 = mt.tensor(raw_sparse_y, chunk_size=12)

        for x, y, is_sparse in [(x1, y1, False), (x2, y2, False),
                                (x3, y3, True), (x4, y4, True)]:
            if is_sparse:
                rx, ry = raw_sparse_x, raw_sparse_y
            else:
                rx, ry = raw_x, raw_y

            sv = [True, False] if not is_sparse else [True]

            for sum_over_features in sv:
                d = manhattan_distances(x, y, sum_over_features)

                result = self.executor.execute_tensor(d, concat=True)[0]
                expected = sk_manhattan_distances(rx, ry, sum_over_features)

                np.testing.assert_almost_equal(result, expected)

                d = manhattan_distances(x, sum_over_features=sum_over_features)

                result = self.executor.execute_tensor(d, concat=True)[0]
                expected = sk_manhattan_distances(
                    rx, sum_over_features=sum_over_features)

                np.testing.assert_almost_equal(result, expected)