dgl.sparse.val_like¶
-
dgl.sparse.
val_like
(mat: dgl.sparse.sparse_matrix.SparseMatrix, val: torch.Tensor) → dgl.sparse.sparse_matrix.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)