dgl.sparse.mulο
- dgl.sparse.mul(A: SparseMatrix | Number | Tensor, B: SparseMatrix | Number | Tensor) SparseMatrix [source]ο
Elementwise multiplication for
SparseMatrix
, equivalent toA * B
.If both
A
andB
are sparse matrices, both of them should be diagonal matrices.- Parameters:
A (SparseMatrix or Scalar) β Sparse matrix or scalar value
B (SparseMatrix or Scalar) β Sparse matrix or scalar value
- Returns:
Sparse matrix
- Return type:
Examples
>>> indices = torch.tensor([[1, 0, 2], [0, 3, 2]]) >>> val = torch.tensor([10, 20, 30]) >>> A = dglsp.spmatrix(indices, val) >>> dglsp.mul(A, 2) SparseMatrix(indices=tensor([[1, 0, 2], [0, 3, 2]]), values=tensor([20, 40, 60]), shape=(3, 4), nnz=3)
>>> D = dglsp.diag(torch.arange(1, 4)) >>> dglsp.mul(D, 2) SparseMatrix(indices=tensor([[0, 1, 2], [0, 1, 2]]), values=tensor([2, 4, 6]), shape=(3, 3), nnz=3)
>>> D = dglsp.diag(torch.arange(1, 4)) >>> dglsp.mul(D, D) SparseMatrix(indices=tensor([[0, 1, 2], [0, 1, 2]]), values=tensor([1, 4, 9]), shape=(3, 3), nnz=3)