dgl.sparse.val_likeο
- dgl.sparse.val_like(mat: SparseMatrix, val: Tensor) SparseMatrix [source]ο
Creates a sparse matrix from an existing sparse matrix using new values.
The new sparse matrix will have the same non-zero indices as the given sparse matrix and use the given values as the new non-zero values.
- Parameters:
mat (SparseMatrix) β An existing sparse matrix with non-zero values
val (torch.Tensor) β The new values of the non-zero elements, a tensor of shape
(nnz)
or(nnz, D)
- Returns:
New sparse matrix
- Return type:
Examples
>>> indices = torch.tensor([[1, 1, 2], [2, 4, 3]]) >>> val = torch.ones(3) >>> A = dglsp.spmatrix(indices, val) >>> A = dglsp.val_like(A, torch.tensor([2, 2, 2])) SparseMatrix(indices=tensor([[1, 1, 2], [2, 4, 3]]), values=tensor([2, 2, 2]), shape=(3, 5), nnz=3)