快捷方式

torch.Tensor.to_sparse_bsc

Tensor.to_sparse_bsc(blocksize, dense_dim) Tensor

将 tensor 转换为具有给定块大小的块稀疏列 (BSC) 存储格式。如果 self 是 strided tensor,则可以指定稠密维度数量,并且将创建一个混合 BSC tensor,其中 dense_dim 为稠密维度,self.dim() - 2 - dense_dim 为批处理维度。

参数
  • blocksize (list, tuple, torch.Size, optional) – 结果 BSC tensor 的块大小。块大小必须是长度为二的元组,其元素必须能整除两个稀疏维度。

  • dense_dim (int, optional) – 结果 BSC tensor 的稠密维度数量。此参数仅当 self 是 strided tensor 时使用,其值必须在 0 到 self tensor 维度减二之间。

示例

>>> dense = torch.randn(10, 10)
>>> sparse = dense.to_sparse_csr()
>>> sparse_bsc = sparse.to_sparse_bsc((5, 5))
>>> sparse_bsc.row_indices()
tensor([0, 1, 0, 1])

>>> dense = torch.zeros(4, 3, 1)
>>> dense[0:2, 0] = dense[0:2, 2] = dense[2:4, 1] = 1
>>> dense.to_sparse_bsc((2, 1), 1)
tensor(ccol_indices=tensor([0, 1, 2, 3]),
       row_indices=tensor([0, 1, 0]),
       values=tensor([[[[1.]],

                       [[1.]]],


                      [[[1.]],

                       [[1.]]],


                      [[[1.]],

                       [[1.]]]]), size=(4, 3, 1), nnz=3,
       layout=torch.sparse_bsc)

文档

查阅 PyTorch 的全面开发者文档

查看文档

教程

获取面向初学者和高级开发者的深度教程

查看教程

资源

查找开发资源并获得问题解答

查看资源