dgl.sparse.spspmm¶
-
dgl.sparse.
spspmm
(A: Union[dgl.sparse.sparse_matrix.SparseMatrix, dgl.sparse.diag_matrix.DiagMatrix], B: Union[dgl.sparse.sparse_matrix.SparseMatrix, dgl.sparse.diag_matrix.DiagMatrix]) → Union[dgl.sparse.sparse_matrix.SparseMatrix, dgl.sparse.diag_matrix.DiagMatrix][source]¶ Multiplies a sparse matrix by a sparse matrix, equivalent to
A @ B
.The non-zero values of the two sparse matrices must be 1D.
- Parameters
A (SparseMatrix or DiagMatrix) – Sparse matrix of shape
(L, M)
B (SparseMatrix or DiagMatrix) – Sparse matrix of shape
(M, N)
- Returns
Matrix of shape
(L, N)
. It is a DiagMatrix object if both matrices are DiagMatrix objects, otherwise a SparseMatrix object.- Return type
Examples
>>> indices1 = torch.tensor([[0, 1, 1], [1, 0, 1]]) >>> val1 = torch.ones(len(row1)) >>> A = dglsp.spmatrix(indices1, val1) >>> indices2 = torch.tensor([[0, 1, 1], [0, 2, 1]]) >>> val2 = torch.ones(len(row2)) >>> B = dglsp.spmatrix(indices2, val2) >>> dglsp.spspmm(A, B) SparseMatrix(indices=tensor([[0, 0, 1, 1, 1], [1, 2, 0, 1, 2]]), values=tensor([1., 1., 1., 1., 1.]), shape=(2, 3), nnz=5)