Efficient version of torch.cat that avoids a copy if there is only a single element in a list
(tensors: List[torch.Tensor], dim: int = 0)
| 130 | |
| 131 | |
| 132 | def cat(tensors: List[torch.Tensor], dim: int = 0): |
| 133 | """ |
| 134 | Efficient version of torch.cat that avoids a copy if there is only a single element in a list |
| 135 | """ |
| 136 | assert isinstance(tensors, (list, tuple)) |
| 137 | if len(tensors) == 1: |
| 138 | return tensors[0] |
| 139 | return torch.cat(tensors, dim) |
no test coverage detected