torch.sparse_bsc_tensor — PyTorch 2.7 documentation (original) (raw)

torch.sparse_bsc_tensor(ccol_indices, row_indices, values, size=None, *, dtype=None, device=None, pin_memory=False, requires_grad=False, check_invariants=None) → Tensor

Constructs a sparse tensor in BSC (Block Compressed Sparse Column)) with specified 2-dimensional blocks at the given ccol_indices and row_indices. Sparse matrix multiplication operations in BSC format are typically faster than that for sparse tensors in COO format. Make you have a look at the note on the data type of the indices.

Note

If the device argument is not specified the device of the givenvalues and indices tensor(s) must match. If, however, the argument is specified the input Tensors will be converted to the given device and in turn determine the device of the constructed sparse tensor.

Parameters

Keyword Arguments

Example::

ccol_indices = [0, 1, 2] row_indices = [0, 1] values = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]] torch.sparse_bsc_tensor(torch.tensor(ccol_indices, dtype=torch.int64), ... torch.tensor(row_indices, dtype=torch.int64), ... torch.tensor(values), dtype=torch.double) tensor(ccol_indices=tensor([0, 1, 2]), row_indices=tensor([0, 1]), values=tensor([[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]]]), size=(2, 2), nnz=2, dtype=torch.float64, layout=torch.sparse_bsc)