dgl.sparse.powerΒΆ
-
dgl.sparse.
power
(A: dgl.sparse.sparse_matrix.SparseMatrix, scalar: Union[numbers.Number, torch.Tensor]) → dgl.sparse.sparse_matrix.SparseMatrix[source]ΒΆ Elementwise exponentiation
SparseMatrix
, equivalent toA ** scalar
.- Parameters
A (SparseMatrix) β Sparse matrix
scalar (Scalar) β Exponent
- Returns
Sparse matrix
- 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) SparseMatrix(indices=tensor([[0, 1, 2], [0, 1, 2]]), values=tensor([1, 4, 9]), shape=(3, 3), nnz=3)