torch_sparse.coalesce(index, value, m, n, op="add") -> (torch.LongTensor, torch.Tensor)
逐行排序index
并删除重复项。通过将重复项映射到一起来删除重复项。对于映射,可以使用任何一种torch_scatter
操作。
参数
返回
import torch
from torch_sparse import coalesce
index = torch.tensor([[1, 0, 1, 0, 2, 1],
[0, 1, 1, 1, 0, 0]])
value = torch.Tensor([[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]])
index, value = coalesce(index, value, m=3, n=2)
------------------------------------------------------------
torch_sparse.transpose(index, value, m, n) -> (torch.LongTensor, torch.Tensor)
对稀疏矩阵的0维和1维进行转置。
参数
返回
import torch
from torch_sparse import transpose
index = torch.tensor([[1, 0, 1, 0, 2, 1], [0, 1, 1, 1, 0, 0]])
value = torch.Tensor([[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7]])
index, value = transpose(index, value, 3, 2)
----------------------------------------------------
print(index)
tensor([[0, 0, 1, 1],
[1, 2, 0, 1]])
print(value)
tensor([[7.0, 9.0],
[5.0, 6.0],
[6.0, 8.0],
[3.0, 4.0]])
torch_sparse.spmm(index, value, m, n, matrix) -> torch.Tensor
一个稀疏矩阵与一个密集矩阵的矩阵乘积。
参数
返回
import torch
from torch_sparse import spmm
index = torch.tensor([[0, 0, 1, 2, 2], [0, 2, 1, 0, 1]])
value = torch.Tensor([1, 2, 4, 1, 3])
matrix = torch.Tensor([[1, 4], [2, 5], [3, 6]])
out = spmm(index, value, 3, 3, matrix)
------------------------------------------
print(out)
tensor([[7.0, 16.0],
[8.0, 20.0],
[7.0, 19.0]])
torch_sparse.spspmm(indexA, valueA, indexB, valueB, m, k, n) -> (torch.LongTensor, torch.Tensor)
两个稀疏张量的矩阵乘积。两个输入稀疏矩阵都需要合并(使用coalesced属性强制)。
参数
返回
import torch
from torch_sparse import spspmm
indexA = torch.tensor([[0, 0, 1, 2, 2], [1, 2, 0, 0, 1]])
valueA = torch.Tensor([1, 2, 3, 4, 5])
indexB = torch.tensor([[0, 2], [1, 0]])
valueB = torch.Tensor([2, 4])
indexC, valueC = spspmm(indexA, valueA, indexB, valueB, 3, 3, 2)
https://github.com/rusty1s/pytorch_sparse