Make `p` listy and the same length as `q`.
(p=None, q=None)
| 78 | |
| 79 | |
| 80 | def listify(p=None, q=None): |
| 81 | "Make `p` listy and the same length as `q`." |
| 82 | if p is None: |
| 83 | p = [] |
| 84 | elif isinstance(p, str): |
| 85 | p = [p] |
| 86 | elif not isinstance(p, Iterable): |
| 87 | p = [p] |
| 88 | n = q if type(q) == int else len(p) if q is None else len(q) |
| 89 | if len(p) == 1: p = p * n |
| 90 | assert len(p) == n, f'List len mismatch ({len(p)} vs {n})' |
| 91 | return list(p) |
| 92 | |
| 93 | |
| 94 | def trainable_params(m: nn.Module): |