Concatenate a list of sparse tensors. Args: inputs (List[SparseTensor]): List of sparse tensors to concatenate.
(inputs: List[SparseTensor], dim: int = 0)
| 795 | return f"SparseTensor(shape={self.shape}, dtype={self.dtype}, device={self.device})" |
| 796 | |
| 797 | def sparse_cat(inputs: List[SparseTensor], dim: int = 0) -> SparseTensor: |
| 798 | """ |
| 799 | Concatenate a list of sparse tensors. |
| 800 | |
| 801 | Args: |
| 802 | inputs (List[SparseTensor]): List of sparse tensors to concatenate. |
| 803 | """ |
| 804 | if dim == 0: |
| 805 | start = 0 |
| 806 | coords = [] |
| 807 | for input in inputs: |
| 808 | coords.append(input.coords.clone()) |
| 809 | coords[-1][:, 0] += start |
| 810 | start += input.shape[0] |
| 811 | coords = torch.cat(coords, dim=0) |
| 812 | feats = torch.cat([input.feats for input in inputs], dim=0) |
| 813 | output = SparseTensor( |
| 814 | coords=coords, |
| 815 | feats=feats, |
| 816 | ) |
| 817 | else: |
| 818 | feats = torch.cat([input.feats for input in inputs], dim=dim) |
| 819 | output = inputs[0].replace(feats) |
| 820 | |
| 821 | return output |
| 822 | |
| 823 | |
| 824 | def sparse_unbind(input: SparseTensor, dim: int) -> List[SparseTensor]: |
no test coverage detected