test_overload.py 426 Bytes
Newer Older
rusty1s's avatar
rusty1s committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import torch
from torch_sparse.tensor import SparseTensor


def test_overload():
    row = torch.tensor([0, 1, 1, 2, 2])
    col = torch.tensor([1, 0, 2, 1, 2])
    mat = SparseTensor(row=row, col=col)

    other = torch.tensor([1, 2, 3]).view(3, 1)
    other + mat
    mat + other
    other * mat
    mat * other

    other = torch.tensor([1, 2, 3]).view(1, 3)
    other + mat
    mat + other
    other * mat
    mat * other