dgl.sparse.div¶
-
dgl.sparse.
div
(A: Union[dgl.sparse.sparse_matrix.SparseMatrix, dgl.sparse.diag_matrix.DiagMatrix], B: Union[dgl.sparse.diag_matrix.DiagMatrix, numbers.Number, torch.Tensor]) → Union[dgl.sparse.sparse_matrix.SparseMatrix, dgl.sparse.diag_matrix.DiagMatrix][source]¶ Elementwise division for
DiagMatrix
andSparseMatrix
, equivalent toA / B
.The supported combinations are shown as follows.
A \ B
DiagMatrix
SparseMatrix
scalar
DiagMatrix
✅
🚫
✅
SparseMatrix
🚫
🚫
✅
scalar
🚫
🚫
🚫
- Parameters
A (SparseMatrix or DiagMatrix) – Sparse or diagonal matrix
B (DiagMatrix or Scalar) – Diagonal matrix or scalar value
- Returns
Diagonal matrix
- Return type
Examples
>>> A = dglsp.diag(torch.arange(1, 4)) >>> B = dglsp.diag(torch.arange(10, 13)) >>> dglsp.div(A, B) DiagMatrix(val=tensor([0.1000, 0.1818, 0.2500]), shape=(3, 3))
>>> A = dglsp.diag(torch.arange(1, 4)) >>> dglsp.div(A, 2) DiagMatrix(val=tensor([0.5000, 1.0000, 1.5000]), shape=(3, 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)