dgl.sparse.add¶
-
dgl.sparse.
add
(A: Union[dgl.sparse.diag_matrix.DiagMatrix, dgl.sparse.sparse_matrix.SparseMatrix], B: Union[dgl.sparse.diag_matrix.DiagMatrix, dgl.sparse.sparse_matrix.SparseMatrix]) → Union[dgl.sparse.diag_matrix.DiagMatrix, dgl.sparse.sparse_matrix.SparseMatrix][source]¶ Elementwise addition for
DiagMatrix
andSparseMatrix
, equivalent toA + B
.The supported combinations are shown as follows.
A \ B
DiagMatrix
SparseMatrix
scalar
DiagMatrix
✅
✅
🚫
SparseMatrix
✅
✅
🚫
scalar
🚫
🚫
🚫
- Parameters
A (DiagMatrix or SparseMatrix) – Diagonal matrix or sparse matrix
B (DiagMatrix or SparseMatrix) – Diagonal matrix or sparse matrix
- Returns
Diagonal matrix if both
A
andB
are diagonal matrices, sparse matrix otherwise- Return type
Examples
>>> indices = torch.tensor([[1, 0, 2], [0, 1, 2]]) >>> val = torch.tensor([10, 20, 30]) >>> A = dglsp.spmatrix(indices, val) >>> B = dglsp.diag(torch.arange(1, 4)) >>> dglsp.add(A, B) SparseMatrix(indices=tensor([[0, 0, 1, 1, 2], [0, 1, 0, 1, 2]]), values=tensor([1, 20, 10, 2, 33]), shape=(3, 3), nnz=5)