dgl.sparse.mul

dgl.sparse.mul(A: Union[dgl.sparse.sparse_matrix.SparseMatrix, dgl.sparse.diag_matrix.DiagMatrix, numbers.Number, torch.Tensor], B: Union[dgl.sparse.sparse_matrix.SparseMatrix, dgl.sparse.diag_matrix.DiagMatrix, numbers.Number, torch.Tensor])Union[dgl.sparse.sparse_matrix.SparseMatrix, dgl.sparse.diag_matrix.DiagMatrix][source]

Elementwise multiplication for DiagMatrix and SparseMatrix, equivalent to A * B.

The supported combinations are shown as follows.

A \ B

DiagMatrix

SparseMatrix

scalar

DiagMatrix

🚫

SparseMatrix

🚫

🚫

scalar

🚫

Parameters
Returns

Either sparse matrix or diagonal matrix

Return type

SparseMatrix or DiagMatrix

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)
DiagMatrix(val=tensor([2, 4, 6]),
           shape=(3, 3))
>>> D = dglsp.diag(torch.arange(1, 4))
>>> dglsp.mul(D, D)
DiagMatrix(val=tensor([1, 4, 9]),
           shape=(3, 3))