test_spmm.py 582 Bytes
Newer Older
1
2
3
from itertools import product

import pytest
rusty1s's avatar
rusty1s committed
4
5
6
import torch
from torch_sparse import spmm

7
8
from .utils import dtypes, devices, tensor

rusty1s's avatar
rusty1s committed
9

10
11
12
13
@pytest.mark.parametrize('dtype,device', product(dtypes, devices))
def test_spmm(dtype, device):
    row = torch.tensor([0, 0, 1, 2, 2], device=device)
    col = torch.tensor([0, 2, 1, 0, 1], device=device)
rusty1s's avatar
rusty1s committed
14
    index = torch.stack([row, col], dim=0)
15
16
    value = tensor([1, 2, 4, 1, 3], dtype, device)
    x = tensor([[1, 4], [2, 5], [3, 6]], dtype, device)
rusty1s's avatar
rusty1s committed
17

18
    out = spmm(index, value, 3, x)
rusty1s's avatar
rusty1s committed
19
    assert out.tolist() == [[7, 16], [8, 20], [7, 19]]