Batch data into lists of length n. The last batch may be shorter.
(iterable, n: int)
| 300 | # ============================================================================ |
| 301 | |
| 302 | def batched(iterable, n: int): |
| 303 | """Batch data into lists of length n. The last batch may be shorter.""" |
| 304 | it = iter(iterable) |
| 305 | while True: |
| 306 | batch = list(islice(it, n)) |
| 307 | if not batch: |
| 308 | break |
| 309 | yield batch |
| 310 | |
| 311 | |
| 312 | def accuracy(output: torch.Tensor, target: torch.Tensor, topk: Tuple[int, ...] = (1,)) -> List[float]: |
no outgoing calls
no test coverage detected