Shortcuts

torch.Tensor.crow_indices

Tensor.crow_indices() IntTensor

self 是布局为 sparse_csr 的稀疏 CSR 张量时,返回包含 self 张量的压缩行索引的张量。 crow_indices 张量的形状严格为 (self.size(0) + 1),并且类型为 int32int64。在使用 MKL 例程(如稀疏矩阵乘法)时,必须使用 int32 索引,以避免向下转换并可能丢失信息。

Example::
>>> csr = torch.eye(5,5).to_sparse_csr()
>>> csr.crow_indices()
张量([0, 1, 2, 3, 4, 5], dtype=torch.int32)
优云智算