torch.sparse — PyTorch 1.10.1 documentation
https://pytorch.org/docs/stable/sparse.htmlConstruction¶. A sparse COO tensor can be constructed by providing the two tensors of indices and values, as well as the size of the sparse tensor (when it cannot be inferred from the indices and values tensors) to a function torch.sparse_coo_tensor(). Suppose we want to define a sparse tensor with the entry 3 at location (0, 2), entry 4 at location (1, 0), and entry 5 at location (1, 2).
TORCH.SPARSE - 知乎 - 知乎专栏
https://zhuanlan.zhihu.com/p/768908082、 torch.sparse.mm ( mat1, mat2) [SOURCE] Performs a matrix multiplication of the sparse matrix mat1 and dense matrix mat2. Similar to torch.mm (), If mat1 is a ( n × m) tensor, mat2 is a ( m × p) tensor, out will be a ( n × p) dense tensor. mat1 need to havesparse_dim = 2. This function also supports backward for both matrices.
python - Column/row slicing a torch sparse tensor - Stack ...
https://stackoverflow.com/questions/5066644003.06.2018 · Possible answer for 2-dimentional sparse indices. Find an answer below, playing with several pytorch methods (torch.eq(), torch.unique(), torch.sort(), etc.) in order to output a compact, sliced tensor of shape (len(idx), len(idx)).I tested several edge cases (unordered idx, v with 0s, i with multiple same index pairs, etc.), though I may have forgot some.