Mercurial > repos > public > sbplib_julia
comparison src/LazyTensors/lazy_tensor_operations.jl @ 456:8f4c31e06689 feature/inflated_tensormapping
Add docs and tests for slice_tuple
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 21 Oct 2020 19:53:36 +0200 |
parents | b86312d14873 |
children | 8fb6a5611c7a |
comparison
equal
deleted
inserted
replaced
455:b86312d14873 | 456:8f4c31e06689 |
---|---|
237 inner_index = slice_tuple(I, Val(range_dim(itm.before)+1), Val(R-range_dim(itm.after))) | 237 inner_index = slice_tuple(I, Val(range_dim(itm.before)+1), Val(R-range_dim(itm.after))) |
238 | 238 |
239 return (view_index, inner_index) | 239 return (view_index, inner_index) |
240 end | 240 end |
241 | 241 |
242 # TODO: Can this be replaced by something more elegant while still being type stable? 2020-10-21 | |
243 # See: | |
244 # https://github.com/JuliaLang/julia/issues/34884 | |
245 # https://github.com/JuliaLang/julia/issues/30386 | |
246 """ | |
247 slice_tuple(t, Val(l), Val(u)) | |
248 | |
249 Get a slice of a tuple in a type stable way. | |
250 Equivalent to t[l:u] but type stable. | |
251 """ | |
242 function slice_tuple(t,::Val{L},::Val{U}) where {L,U} | 252 function slice_tuple(t,::Val{L},::Val{U}) where {L,U} |
243 return ntuple(i->t[i+L-1], U-L+1) | 253 return ntuple(i->t[i+L-1], U-L+1) |
244 end | 254 end |
245 | 255 |
246 flatten_tuple(t::NTuple{N, Number} where N) = t | 256 flatten_tuple(t::NTuple{N, Number} where N) = t |