| 1482 | def is_pow2(v): return v > 0 and v & (v - 1) == 0 |
| 1483 | # pad dimension i to amt with invalids |
| 1484 | def ipad(t, i, amt): |
| 1485 | shape = (None,)*i + (amt,) + (None,)*(t.ndim-i-1) |
| 1486 | return Tensor(True, device=t.device).expand(t.shape).pad_to(shape).where(t.pad_to(shape), Invalid) if amt != t.shape[i] else t |
| 1487 | # align a dimension, use at to specify the dimension to pad in, defaults to first |
| 1488 | def pad_align(t, dim, at=None, force=False): |
| 1489 | # align to 64 pixels when height is real, otherwise 64 bytes is sufficient |