Mercurial > repos > public > sbplib_julia
comparison src/LazyTensors/tuple_manipulation.jl @ 1355:102ebdaf7c11 feature/variable_derivatives
Merge default
| author | Jonatan Werpers <jonatan@werpers.com> |
|---|---|
| date | Wed, 08 Feb 2023 21:21:28 +0100 |
| parents | 07c213167f7c |
| children | 5bfb182e24dc |
comparison
equal
deleted
inserted
replaced
| 1210:fa0800591306 | 1355:102ebdaf7c11 |
|---|---|
| 73 """ | 73 """ |
| 74 flatten_tuple(t::NTuple{N, Number} where N) = t | 74 flatten_tuple(t::NTuple{N, Number} where N) = t |
| 75 flatten_tuple(t::Tuple) = ((flatten_tuple.(t)...)...,) # simplify? | 75 flatten_tuple(t::Tuple) = ((flatten_tuple.(t)...)...,) # simplify? |
| 76 flatten_tuple(ts::Vararg) = flatten_tuple(ts) | 76 flatten_tuple(ts::Vararg) = flatten_tuple(ts) |
| 77 | 77 |
| 78 """ | |
| 79 left_pad_tuple(t, val, N) | |
| 78 | 80 |
| 81 Left pad the tuple `t` to length `N` using the value `val`. | |
| 82 """ | |
| 79 function left_pad_tuple(t, val, N) | 83 function left_pad_tuple(t, val, N) |
| 80 if N < length(t) | 84 if N < length(t) |
| 81 throw(DomainError(N, "Can't pad tuple of length $(length(t)) to $N elements")) | 85 throw(DomainError(N, "Can't pad tuple of length $(length(t)) to $N elements")) |
| 82 end | 86 end |
| 83 | 87 |
| 84 padding = ntuple(i->val, N-length(t)) | 88 padding = ntuple(i->val, N-length(t)) |
| 85 return (padding..., t...) | 89 return (padding..., t...) |
| 86 end | 90 end |
| 87 | 91 |
| 92 """ | |
| 93 right_pad_tuple(t, val, N) | |
| 94 | |
| 95 Right pad the tuple `t` to length `N` using the value `val`. | |
| 96 """ | |
| 88 function right_pad_tuple(t, val, N) | 97 function right_pad_tuple(t, val, N) |
| 89 if N < length(t) | 98 if N < length(t) |
| 90 throw(DomainError(N, "Can't pad tuple of length $(length(t)) to $N elements")) | 99 throw(DomainError(N, "Can't pad tuple of length $(length(t)) to $N elements")) |
| 91 end | 100 end |
| 92 | 101 |
