test_grid.py 944 Bytes
Newer Older
rusty1s's avatar
rusty1s committed
1
2
3
4
5
from itertools import product

import pytest
from torch_cluster import grid_cluster

rusty1s's avatar
rusty1s committed
6
from .utils import dtypes, devices, tensor
rusty1s's avatar
rusty1s committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

tests = [{
    'pos': [2, 6],
    'size': [5],
    'cluster': [0, 0],
}, {
    'pos': [2, 6],
    'size': [5],
    'start': [0],
    'cluster': [0, 1],
}, {
    'pos': [[0, 0], [11, 9], [2, 8], [2, 2], [8, 3]],
    'size': [5, 5],
    'cluster': [0, 5, 3, 0, 1],
}, {
    'pos': [[0, 0], [11, 9], [2, 8], [2, 2], [8, 3]],
    'size': [5, 5],
    'end': [19, 19],
    'cluster': [0, 6, 4, 0, 1],
}]


rusty1s's avatar
rusty1s committed
29
@pytest.mark.parametrize('test,dtype,device', product(tests, dtypes, devices))
rusty1s's avatar
typo  
rusty1s committed
30
def test_grid_cluster(test, dtype, device):
rusty1s's avatar
rusty1s committed
31
32
33
34
    pos = tensor(test['pos'], dtype, device)
    size = tensor(test['size'], dtype, device)
    start = tensor(test.get('start'), dtype, device)
    end = tensor(test.get('end'), dtype, device)
rusty1s's avatar
rusty1s committed
35
36

    cluster = grid_cluster(pos, size, start, end)
rusty1s's avatar
rusty1s committed
37
    assert cluster.tolist() == test['cluster']