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 to A ** scalar.

Parameters
  • A (SparseMatrix) – Sparse matrix

  • scalar (Scalar) – Exponent

Returns

Sparse matrix

Return type

SparseMatrix

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)