torch.Tensor.crow_indices¶
- Tensor.crow_indices() IntTensor ¶
當
self
是佈局為sparse_csr
的稀疏 CSR 張量時,傳回包含self
張量的壓縮列索引的張量。crow_indices
張量的形狀嚴格為 (self
.size(0) + 1),類型為int32
或int64
。 當使用諸如稀疏矩陣乘法之類的 MKL 常式時,必須使用int32
索引,以避免向下轉換並可能遺失資訊。- 範例:
>>> csr = torch.eye(5,5).to_sparse_csr() >>> csr.crow_indices() tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)