| 1 |
from itertools import product |
| 2 |
|
| 3 |
import pytest |
| 4 |
import torch |
| 5 |
from torch_scatter import (gather_coo, gather_csr, scatter, segment_coo, |
| 6 |
segment_csr) |
| 7 |
from torch_scatter.testing import devices, grad_dtypes, reductions, tensor |
| 8 |
|
| 9 |
|
| 10 |
@pytest.mark.parametrize('reduce,dtype,device', |
| 11 |
product(reductions, grad_dtypes, devices)) |
| 12 |
def test_zero_elements(reduce, dtype, device): |
| 13 |
x = torch.randn(0, 0, 0, 16, dtype=dtype, device=device, |
| 14 |
requires_grad=True) |
| 15 |
index = tensor([], torch.long, device) |
| 16 |
indptr = tensor([], torch.long, device) |
| 17 |
|
| 18 |
out = scatter(x, index, dim=0, dim_size=0, reduce=reduce) |
| 19 |
out.backward(torch.randn_like(out)) |
| 20 |
assert out.size() == (0, 0, 0, 16) |
| 21 |
|
| 22 |
out = segment_coo(x, index, dim_size=0, reduce=reduce) |
| 23 |
out.backward(torch.randn_like(out)) |
| 24 |
assert out.size() == (0, 0, 0, 16) |
| 25 |
|
| 26 |
out = gather_coo(x, index) |
| 27 |
out.backward(torch.randn_like(out)) |
| 28 |
assert out.size() == (0, 0, 0, 16) |
| 29 |
|
| 30 |
out = segment_csr(x, indptr, reduce=reduce) |
| 31 |
out.backward(torch.randn_like(out)) |
| 32 |
assert out.size() == (0, 0, 0, 16) |
| 33 |
|
| 34 |
out = gather_csr(x, indptr) |
| 35 |
out.backward(torch.randn_like(out)) |
| 36 |
assert out.size() == (0, 0, 0, 16) |