Return the device of the data which can be either a tensor or a list/dict of tensors.
(data)
| 1159 | |
| 1160 | |
| 1161 | def context_of(data): |
| 1162 | """Return the device of the data which can be either a tensor or a list/dict of tensors.""" |
| 1163 | if isinstance(data, Mapping): |
| 1164 | return F.context(next(iter(data.values()))) |
| 1165 | elif is_listlike(data): |
| 1166 | return F.context(next(iter(data))) |
| 1167 | else: |
| 1168 | return F.context(data) |
| 1169 | |
| 1170 | |
| 1171 | def dtype_of(data): |
no test coverage detected