MCPcopy
hub / github.com/dmlc/dgl / val_like

Function val_like

python/dgl/sparse/sparse_matrix.py:1108–1143  ·  view source on GitHub ↗

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

(mat: SparseMatrix, val: torch.Tensor)

Source from the content-addressed store, hash-verified

1106
1107
1108def val_like(mat: SparseMatrix, val: torch.Tensor) -> SparseMatrix:
1109 """Creates a sparse matrix from an existing sparse matrix using new values.
1110
1111 The new sparse matrix will have the same non-zero indices as the given
1112 sparse matrix and use the given values as the new non-zero values.
1113
1114 Parameters
1115 ----------
1116 mat : SparseMatrix
1117 An existing sparse matrix with non-zero values
1118 val : torch.Tensor
1119 The new values of the non-zero elements, a tensor of shape ``(nnz)`` or
1120 ``(nnz, D)``
1121
1122 Returns
1123 -------
1124 SparseMatrix
1125 New sparse matrix
1126
1127 Examples
1128 --------
1129
1130 >>> indices = torch.tensor([[1, 1, 2], [2, 4, 3]])
1131 >>> val = torch.ones(3)
1132 >>> A = dglsp.spmatrix(indices, val)
1133 >>> A = dglsp.val_like(A, torch.tensor([2, 2, 2]))
1134 SparseMatrix(indices=tensor([[1, 1, 2],
1135 [2, 4, 3]]),
1136 values=tensor([2, 2, 2]),
1137 shape=(3, 5), nnz=3)
1138 """
1139 assert (
1140 val.dim() <= 2
1141 ), "The values of a SparseMatrix can only be scalars or vectors."
1142
1143 return SparseMatrix(torch.ops.dgl_sparse.val_like(mat.c_sparse_matrix, val))
1144
1145
1146def diag(

Callers 15

test_spspmulFunction · 0.90
test_val_likeFunction · 0.90
test_sample_rowwiseFunction · 0.90
test_sample_columnwiseFunction · 0.90
test_spmmFunction · 0.90
test_bspmmFunction · 0.90
test_spspmmFunction · 0.90
test_sparse_diag_mmFunction · 0.90
test_diag_sparse_mmFunction · 0.90
sp_mulFunction · 0.85
sp_divFunction · 0.85
sp_powerFunction · 0.85

Calls 1

SparseMatrixClass · 0.70

Tested by 9

test_spspmulFunction · 0.72
test_val_likeFunction · 0.72
test_sample_rowwiseFunction · 0.72
test_sample_columnwiseFunction · 0.72
test_spmmFunction · 0.72
test_bspmmFunction · 0.72
test_spspmmFunction · 0.72
test_sparse_diag_mmFunction · 0.72
test_diag_sparse_mmFunction · 0.72