Concatenates any number of tuples (s, V) elementwise. :param dim: dimension along which to concatenate when viewed as the `dim` index for the scalar-channel tensors. This means that `dim=-1` will be applied as `dim=-2` for the vector-chan
(*args, dim=-1)
| 16 | |
| 17 | |
| 18 | def tuple_cat(*args, dim=-1): |
| 19 | ''' |
| 20 | Concatenates any number of tuples (s, V) elementwise. |
| 21 | |
| 22 | :param dim: dimension along which to concatenate when viewed |
| 23 | as the `dim` index for the scalar-channel tensors. |
| 24 | This means that `dim=-1` will be applied as |
| 25 | `dim=-2` for the vector-channel tensors. |
| 26 | ''' |
| 27 | dim %= len(args[0][0].shape) |
| 28 | s_args, v_args = list(zip(*args)) |
| 29 | return torch.cat(s_args, dim=dim), torch.cat(v_args, dim=dim) |
| 30 | |
| 31 | |
| 32 | def tuple_index(x, idx): |