Exemplo n.º 1
0
    def testHaversineDistancesExecution(self):
        raw_x = np.random.rand(30, 2)
        raw_y = np.random.rand(21, 2)

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

        # multiple chunks
        x2 = mt.tensor(raw_x, chunk_size=(11, 1))
        y2 = mt.tensor(raw_y, chunk_size=(17, 1))

        for x, y in [(x1, y1), (x2, y2)]:
            for use_sklearn in [True, False]:
                distance = haversine_distances(x, y)
                distance.op._use_sklearn = use_sklearn

                result = self.executor.execute_tensor(distance, concat=True)[0]
                expected = sk_haversine_distances(raw_x, raw_y)
                np.testing.assert_array_equal(result, expected)

                # test x is y
                distance = haversine_distances(x)
                distance.op._use_sklearn = use_sklearn

                result = self.executor.execute_tensor(distance, concat=True)[0]
                expected = sk_haversine_distances(raw_x, raw_x)
                np.testing.assert_array_equal(result, expected)
Exemplo n.º 2
0
def test_haversine_distances_execution(setup, x, y, use_sklearn):
    distance = haversine_distances(x, y)
    distance.op._use_sklearn = use_sklearn

    result = distance.execute().fetch()
    expected = sk_haversine_distances(raw_x, raw_y)
    np.testing.assert_array_equal(result, expected)

    # test x is y
    distance = haversine_distances(x)
    distance.op._use_sklearn = use_sklearn

    result = distance.execute().fetch()
    expected = sk_haversine_distances(raw_x, raw_x)
    np.testing.assert_array_equal(result, expected)
Exemplo n.º 3
0
def test_haversine_distances_op():
    # shape[1] != 2
    with pytest.raises(ValueError):
        haversine_distances(mt.random.rand(10, 3))

    # shape[1] != 2
    with pytest.raises(ValueError):
        haversine_distances(mt.random.rand(10, 2), mt.random.rand(11, 3))

    # cannot support sparse
    with pytest.raises(TypeError):
        haversine_distances(mt.random.randint(10, size=(10, 2), density=0.5))
Exemplo n.º 4
0
    def testHaversineDistancesOp(self):
        # shape[1] != 2
        with self.assertRaises(ValueError):
            haversine_distances(mt.random.rand(10, 3))

        # shape[1] != 2
        with self.assertRaises(ValueError):
            haversine_distances(mt.random.rand(10, 2), mt.random.rand(11, 3))

        # cannot support sparse
        with self.assertRaises(TypeError):
            haversine_distances(
                mt.random.randint(10, size=(10, 2), density=0.5))