torch.spmm矩阵乘法

Example:

import torch
indices = torch.tensor([[0,1],
                        [0,1]])
values = torch.tensor([2,3])
shape = torch.Size((2,2))
s = torch.sparse.FloatTensor(indices,values,shape)
print(s)

d = torch.tensor([[1,2],
                  [3,4]])

print(d)
print(torch.spmm(s,d))
"""
tensor(indices=tensor([[0, 1],
                       [0, 1]]),
       values=tensor([2, 3]),
       size=(2, 2), nnz=2, layout=torch.sparse_coo)
tensor([[1, 2],
        [3, 4]])
tensor([[ 2,  4],
        [ 9, 12]])
"""

 

posted @ 2022-03-15 19:45  图神经网络  阅读(1140)  评论(0编辑  收藏  举报
Live2D