dgl.sparse.power¶
-
dgl.sparse.
power
(A: Union[dgl.sparse.sparse_matrix.SparseMatrix, dgl.sparse.diag_matrix.DiagMatrix], scalar: Union[numbers.Number, torch.Tensor]) → Union[dgl.sparse.sparse_matrix.SparseMatrix, dgl.sparse.diag_matrix.DiagMatrix][source]¶ Elementwise exponentiation for
DiagMatrix
andSparseMatrix
, equivalent toA ** scalar
.The supported combinations are shown as follows.
A \ B
DiagMatrix
SparseMatrix
scalar
DiagMatrix
🚫
🚫
✅
SparseMatrix
🚫
🚫
✅
scalar
🚫
🚫
🚫
- Parameters
A (SparseMatrix or DiagMatrix) – Sparse matrix or diagonal matrix
scalar (Scalar) – Exponent
- Returns
Sparse matrix or diagonal matrix, same type as A
- Return type
Examples
>>> indices = torch.tensor([[1, 0, 2], [0, 3, 2]]) >>> val = torch.tensor([10, 20, 30]) >>> A = dglsp.spmatrix(indices, val) >>> dglsp.power(A, 2) SparseMatrix(indices=tensor([[1, 0, 2], [0, 3, 2]]), values=tensor([100, 400, 900]), shape=(3, 4), nnz=3)
>>> D = dglsp.diag(torch.arange(1, 4)) >>> dglsp.power(D, 2) DiagMatrix(val=tensor([1, 4, 9]), shape=(3, 3))