Mercurial > repos > public > sbplib_julia
comparison src/LazyTensors/tuple_manipulation.jl @ 1073:5a3281429a48 feature/variable_derivatives
Merge feature/variable_derivatives
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 24 Mar 2022 12:35:14 +0100 |
parents | 0905cec43d2e |
children | 423a6442efc3 |
comparison
equal
deleted
inserted
replaced
1068:0b0444adacd3 | 1073:5a3281429a48 |
---|---|
72 Takes a nested tuple and flattens the whole structure | 72 Takes a nested tuple and flattens the whole structure |
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 | |
78 | |
79 function left_pad_tuple(t, val, N) | |
80 if N < length(t) | |
81 throw(DomainError(N, "Can't pad tuple of length $(length(t)) to $N elements")) | |
82 end | |
83 | |
84 padding = ntuple(i->val, N-length(t)) | |
85 return (padding..., t...) | |
86 end | |
87 | |
88 function right_pad_tuple(t, val, N) | |
89 if N < length(t) | |
90 throw(DomainError(N, "Can't pad tuple of length $(length(t)) to $N elements")) | |
91 end | |
92 | |
93 padding = ntuple(i->val, N-length(t)) | |
94 return (t..., padding...) | |
95 end | |
96 |