dgl.sparse.div

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

Elementwise division for SparseMatrix, equivalent to A / B.

If both A and B are sparse matrices, both of them should be diagonal matrices.

Parameters
Returns

Sparse matrix

Return type

SparseMatrix

Examples

>>> A = dglsp.diag(torch.arange(1, 4))
>>> B = dglsp.diag(torch.arange(10, 13))
>>> dglsp.div(A, B)
SparseMatrix(indices=tensor([[0, 1, 2],
                             [0, 1, 2]]),
             values=tensor([0.1000, 0.1818, 0.2500]),
             shape=(3, 3), nnz=3)
>>> A = dglsp.diag(torch.arange(1, 4))
>>> dglsp.div(A, 2)
SparseMatrix(indices=tensor([[0, 1, 2],
                             [0, 1, 2]]),
             values=tensor([0.5000, 1.0000, 1.5000]),
             shape=(3, 3), nnz=3)
>>> indices = torch.tensor([[1, 0, 2], [0, 3, 2]])
>>> val = torch.tensor([1, 2, 3])
>>> A = dglsp.spmatrix(indices, val, shape=(3, 4))
>>> dglsp.div(A, 2)
SparseMatrix(indices=tensor([[1, 0, 2],
                             [0, 3, 2]]),
             values=tensor([0.5000, 1.0000, 1.5000]),
             shape=(3, 4), nnz=3)