dgl.sparse.DiagMatrix.to_sparse¶
-
DiagMatrix.
to_sparse
() → dgl.sparse.sparse_matrix.SparseMatrix[source]¶ Returns a copy in sparse matrix format of the diagonal matrix.
- Returns
The copy in sparse matrix format
- Return type
Examples
>>> import torch >>> val = torch.ones(5) >>> D = dglsp.diag(val) >>> D.to_sparse() SparseMatrix(indices=tensor([[0, 1, 2, 3, 4], [0, 1, 2, 3, 4]]), values=tensor([1., 1., 1., 1., 1.]), shape=(5, 5), nnz=5)