Returns a copy of `tup` with `dim` values by either shortened or padded with `pad_val` as necessary.
(vals: Any, dim: int, pad_val: Any = 0, pad_from_start: bool = False)
| 179 | |
| 180 | |
| 181 | def ensure_tuple_size(vals: Any, dim: int, pad_val: Any = 0, pad_from_start: bool = False) -> tuple: |
| 182 | """ |
| 183 | Returns a copy of `tup` with `dim` values by either shortened or padded with `pad_val` as necessary. |
| 184 | """ |
| 185 | tup = ensure_tuple(vals) |
| 186 | pad_dim = dim - len(tup) |
| 187 | if pad_dim <= 0: |
| 188 | return tup[:dim] |
| 189 | if pad_from_start: |
| 190 | return (pad_val,) * pad_dim + tup |
| 191 | return tup + (pad_val,) * pad_dim |
| 192 | |
| 193 | |
| 194 | def ensure_tuple_rep(tup: Any, dim: int) -> tuple[Any, ...]: |
no test coverage detected
searching dependent graphs…