test_ffi.py 884 Bytes
Newer Older
rusty1s's avatar
bugfix  
rusty1s committed
1
import torch
rusty1s's avatar
rusty1s committed
2
from torch_cluster.functions.utils.ffi import ffi_serial, ffi_grid
rusty1s's avatar
bugfix  
rusty1s committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16


def test_serial_cpu():
    row = torch.LongTensor([0, 0, 1, 1, 1, 2, 2, 2, 3, 3])
    col = torch.LongTensor([1, 2, 0, 2, 3, 0, 1, 3, 1, 2])
    degree = torch.LongTensor([2, 3, 3, 2])
    cluster = ffi_serial(row, col, degree)
    expected_cluster = [0, 0, 2, 2]
    assert cluster.tolist() == expected_cluster

    weight = torch.Tensor([1, 2, 1, 3, 2, 2, 3, 3, 2, 3])
    cluster = ffi_serial(row, col, degree, weight)
    expected_cluster = [0, 1, 0, 1]
    assert cluster.tolist() == expected_cluster
rusty1s's avatar
rusty1s committed
17
18
19
20
21
22
23
24
25


def test_grid_cpu():
    position = torch.Tensor([[0, 0], [11, 9], [2, 8], [2, 2], [8, 3]])
    size = torch.Tensor([5, 5])
    count = torch.LongTensor([3, 2])
    cluster = ffi_grid(position, size, count)
    expected_cluster = [0, 5, 1, 0, 2]
    assert cluster.tolist() == expected_cluster