評價此頁

torch.Tensor.crow_indices#

Tensor.crow_indices() IntTensor#

返回包含 self 張量在 selfsparse_csr 佈局的稀疏 CSR 張量時的壓縮行索引的張量。 crow_indices 張量的形狀嚴格為 (self.size(0) + 1),型別為 int32int64。在使用 MKL 例程(如稀疏矩陣乘法)時,為了避免向下轉換並可能丟失資訊,必須使用 int32 索引。

示例

>>> csr = torch.eye(5,5).to_sparse_csr()
>>> csr.crow_indices()
tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)