Mercurial > repos > public > sbplib_julia
diff 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 |
line wrap: on
line diff
--- a/src/LazyTensors/tuple_manipulation.jl Wed Mar 23 13:32:51 2022 +0100 +++ b/src/LazyTensors/tuple_manipulation.jl Thu Mar 24 12:35:14 2022 +0100 @@ -74,3 +74,23 @@ flatten_tuple(t::NTuple{N, Number} where N) = t flatten_tuple(t::Tuple) = ((flatten_tuple.(t)...)...,) # simplify? flatten_tuple(ts::Vararg) = flatten_tuple(ts) + + +function left_pad_tuple(t, val, N) + if N < length(t) + throw(DomainError(N, "Can't pad tuple of length $(length(t)) to $N elements")) + end + + padding = ntuple(i->val, N-length(t)) + return (padding..., t...) +end + +function right_pad_tuple(t, val, N) + if N < length(t) + throw(DomainError(N, "Can't pad tuple of length $(length(t)) to $N elements")) + end + + padding = ntuple(i->val, N-length(t)) + return (t..., padding...) +end +