# dgl.sparse.mulΒΆ

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

Elementwise multiplication for `SparseMatrix`, equivalent to `A * B`.

If both `A` and `B` 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

SparseMatrix

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)
```