(self, other, op)
| 124 | return 'TensorList: \n' + repr(self.tensors) |
| 125 | |
| 126 | def _apply(self, other, op): |
| 127 | if isinstance(other, (list, tuple, TensorList)) or ( |
| 128 | isinstance(other, torch.Tensor) and ( |
| 129 | other.numel() > 1 or other.ndim > 1 |
| 130 | ) |
| 131 | ): |
| 132 | assert len(other) == len(self.tensors) |
| 133 | return TensorList([op(u, v) for u, v in zip(self.tensors, other)]) |
| 134 | elif isinstance(other, numbers.Number) or ( |
| 135 | isinstance(other, torch.Tensor) and ( |
| 136 | other.numel() == 1 and other.ndim <= 1 |
| 137 | ) |
| 138 | ): |
| 139 | return TensorList([op(u, other) for u in self.tensors]) |
| 140 | else: |
| 141 | raise TypeError( |
| 142 | f'unsupported operand for *: "TensorList" and "{type(other)}"' |
| 143 | ) |
no test coverage detected