torch.Tensor.crow_indices

Tensor.crow_indices() IntTensor

self是一个布局为sparse_csr的稀疏CSR张量时,此函数返回包含self张量压缩行索引的张量。该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)
本页目录