dgl.sparse.SparseMatrix.neg

SparseMatrix.neg() SparseMatrix

Returns a new sparse matrix with the negation of the original nonzero values, equivalent to -A.

Returns:

Negation of the sparse matrix

Return type:

SparseMatrix

Examples

>>> indices = torch.tensor([[1, 1, 3], [1, 2, 3]])
>>> val = torch.tensor([1., 1., 2.])
>>> A = dglsp.spmatrix(indices, val)
>>> A = -A
SparseMatrix(indices=tensor([[1, 1, 3],
                             [1, 2, 3]]),
             values=tensor([-1., -1., -2.]),
             shape=(4, 4), nnz=3)