test_saint.py 1.3 KB
Newer Older
rusty1s's avatar
rusty1s committed
1
2
3
import pytest
import torch
from torch_sparse.tensor import SparseTensor
rusty1s's avatar
rusty1s committed
4
from torch_sparse.saint import subgraph
rusty1s's avatar
rusty1s committed
5
6
7
8

from .utils import devices


rusty1s's avatar
rusty1s committed
9
10
11
12
13
14
15
16
17
18
@pytest.mark.parametrize('device', devices)
def test_subgraph(device):
    row = torch.tensor([0, 0, 1, 1, 2, 2, 2, 3, 3, 4])
    col = torch.tensor([1, 2, 0, 2, 0, 1, 3, 2, 4, 3])
    adj = SparseTensor(row=row, col=col).to(device)
    node_idx = torch.tensor([0, 1, 2])

    adj, edge_index = subgraph(adj, node_idx)


rusty1s's avatar
rusty1s committed
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
@pytest.mark.parametrize('device', devices)
def test_sample_node(device):
    row = torch.tensor([0, 0, 1, 1, 2, 2, 2, 3, 3, 4])
    col = torch.tensor([1, 2, 0, 2, 0, 1, 3, 2, 4, 3])
    adj = SparseTensor(row=row, col=col).to(device)

    adj, perm = adj.sample_node(num_nodes=3)


@pytest.mark.parametrize('device', devices)
def test_sample_edge(device):
    row = torch.tensor([0, 0, 1, 1, 2, 2, 2, 3, 3, 4])
    col = torch.tensor([1, 2, 0, 2, 0, 1, 3, 2, 4, 3])
    adj = SparseTensor(row=row, col=col).to(device)

    adj, perm = adj.sample_edge(num_edges=3)


@pytest.mark.parametrize('device', devices)
def test_sample_rw(device):
    row = torch.tensor([0, 0, 1, 1, 2, 2, 2, 3, 3, 4])
    col = torch.tensor([1, 2, 0, 2, 0, 1, 3, 2, 4, 3])
    adj = SparseTensor(row=row, col=col).to(device)

    adj, perm = adj.sample_rw(num_root_nodes=3, walk_length=2)