Concatenate a list of sparse tensors. Args: inputs (List[SparseTensor]): List of sparse tensors to concatenate.
(inputs: List[SparseTensor], dim: int = 0)
| 418 | |
| 419 | |
| 420 | def sparse_cat(inputs: List[SparseTensor], dim: int = 0) -> SparseTensor: |
| 421 | """ |
| 422 | Concatenate a list of sparse tensors. |
| 423 | |
| 424 | Args: |
| 425 | inputs (List[SparseTensor]): List of sparse tensors to concatenate. |
| 426 | """ |
| 427 | if dim == 0: |
| 428 | start = 0 |
| 429 | coords = [] |
| 430 | for input in inputs: |
| 431 | coords.append(input.coords.clone()) |
| 432 | coords[-1][:, 0] += start |
| 433 | start += input.shape[0] |
| 434 | coords = torch.cat(coords, dim=0) |
| 435 | feats = torch.cat([input.feats for input in inputs], dim=0) |
| 436 | output = SparseTensor( |
| 437 | coords=coords, |
| 438 | feats=feats, |
| 439 | ) |
| 440 | else: |
| 441 | feats = torch.cat([input.feats for input in inputs], dim=dim) |
| 442 | output = inputs[0].replace(feats) |
| 443 | |
| 444 | return output |
| 445 | |
| 446 | |
| 447 | def sparse_unbind(input: SparseTensor, dim: int) -> List[SparseTensor]: |
nothing calls this directly
no test coverage detected