dgl.sparse.SparseMatrix.int
- SparseMatrix.int()[source]
将矩阵值转换为int32数据类型。如果矩阵已经使用int数据类型,将返回原始矩阵。
- Returns:
包含整数值的矩阵
- Return type:
对角矩阵
示例
>>> indices = torch.tensor([[1, 1, 2], [1, 2, 0]]) >>> A = dglsp.spmatrix(indices, shape=(3, 4)) >>> A.int() SparseMatrix(indices=tensor([[1, 1, 2], [1, 2, 0]]), values=tensor([1, 1, 1], dtype=torch.int32), shape=(3, 4), nnz=3)