Mercurial > repos > public > sbplib_julia
comparison src/LazyTensors/tuple_manipulation.jl @ 1094:672610322206 feature/dissipation_operators
Add docs for left_pad_tuple and right_pad_tuple
| author | Jonatan Werpers <jonatan@werpers.com> |
|---|---|
| date | Tue, 10 May 2022 20:41:35 +0200 |
| parents | 423a6442efc3 |
| children | 07c213167f7c |
comparison
equal
deleted
inserted
replaced
| 1087:423a6442efc3 | 1094:672610322206 |
|---|---|
| 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 # REVIEW: Add documentation | 78 """ |
| 79 left_pad_tuple(t, val, N) | |
| 80 | |
| 81 Left pad the `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 |
| 88 # REVIEW: Add documentation | 92 """ |
| 93 right_pad_tuple(t, val, N) | |
| 94 | |
| 95 Right pad the `t` to length `N` using the value `val`. | |
| 96 """ | |
| 89 function right_pad_tuple(t, val, N) | 97 function right_pad_tuple(t, val, N) |
| 90 if N < length(t) | 98 if N < length(t) |
| 91 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")) |
| 92 end | 100 end |
| 93 | 101 |
