|
2 | 2 |
|
3 | 3 | import pytest |
4 | 4 | import torch |
5 | | -from torch_sparse import transpose, transpose_matrix |
| 5 | +from torch_sparse import transpose |
6 | 6 |
|
7 | 7 | from .utils import dtypes, devices, tensor |
8 | 8 |
|
9 | 9 |
|
10 | | -def test_transpose(): |
11 | | - row = torch.tensor([1, 0, 1, 0, 2, 1]) |
12 | | - col = torch.tensor([0, 1, 1, 1, 0, 0]) |
| 10 | +@pytest.mark.parametrize('dtype,device', product(dtypes, devices)) |
| 11 | +def test_transpose_matrix(dtype, device): |
| 12 | + row = torch.tensor([1, 0, 1, 2], device=device) |
| 13 | + col = torch.tensor([0, 1, 1, 0], device=device) |
13 | 14 | index = torch.stack([row, col], dim=0) |
14 | | - value = torch.tensor([[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]]) |
| 15 | + value = tensor([1, 2, 3, 4], dtype, device) |
15 | 16 |
|
16 | 17 | index, value = transpose(index, value, m=3, n=2) |
17 | 18 | assert index.tolist() == [[0, 0, 1, 1], [1, 2, 0, 1]] |
18 | | - assert value.tolist() == [[7, 9], [5, 6], [6, 8], [3, 4]] |
| 19 | + assert value.tolist() == [1, 4, 2, 3] |
19 | 20 |
|
20 | 21 |
|
21 | 22 | @pytest.mark.parametrize('dtype,device', product(dtypes, devices)) |
22 | | -def test_transpose_matrix(dtype, device): |
23 | | - row = torch.tensor([1, 0, 1, 2], device=device) |
24 | | - col = torch.tensor([0, 1, 1, 0], device=device) |
| 23 | +def test_transpose(dtype, device): |
| 24 | + row = torch.tensor([1, 0, 1, 0, 2, 1], device=device) |
| 25 | + col = torch.tensor([0, 1, 1, 1, 0, 0], device=device) |
25 | 26 | index = torch.stack([row, col], dim=0) |
26 | | - value = tensor([1, 2, 3, 4], dtype, device) |
| 27 | + value = tensor([[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]], dtype, |
| 28 | + device) |
27 | 29 |
|
28 | | - index, value = transpose_matrix(index, value, m=3, n=2) |
| 30 | + index, value = transpose(index, value, m=3, n=2) |
29 | 31 | assert index.tolist() == [[0, 0, 1, 1], [1, 2, 0, 1]] |
30 | | - assert value.tolist() == [1, 4, 2, 3] |
| 32 | + assert value.tolist() == [[7, 9], [5, 6], [6, 8], [3, 4]] |
0 commit comments