diff src/LazyTensors/tuple_manipulation.jl @ 1227:06b983f0d236 refactor/LazyTensors/tuple_manipulation

Delete complicated versions of split_tuple and slice_tuple
author Jonatan Werpers <jonatan@werpers.com>
date Sat, 18 Feb 2023 21:56:29 +0100
parents ea5b4fca85e0
children 73f262a0a384
line wrap: on
line diff
--- a/src/LazyTensors/tuple_manipulation.jl	Sat Feb 18 21:55:55 2023 +0100
+++ b/src/LazyTensors/tuple_manipulation.jl	Sat Feb 18 21:56:29 2023 +0100
@@ -19,54 +19,13 @@
  * `length(I_middle) == dim_index`
 """
 function split_index(::Val{dim_before}, ::Val{dim_view}, ::Val{dim_index}, ::Val{dim_after}, I...) where {dim_before,dim_view, dim_index,dim_after}
-    I_before, I_middle, I_after = split_tuple(I, Val(dim_before), Val(dim_index))
+    I_before, I_middle, I_after = @inline split_tuple(I, (dim_before, dim_index, dim_after))
 
     view_index = (I_before..., ntuple((i)->:, dim_view)..., I_after...)
 
     return view_index, I_middle
 end
-# TBD: If the nice split_tuple works, can this be cleaned up as well?
 
-# TODO: Can this be replaced by something more elegant while still being type stable? 2020-10-21
-# See:
-# https://github.com/JuliaLang/julia/issues/34884
-# https://github.com/JuliaLang/julia/issues/30386
-"""
-    slice_tuple(t, Val(l), Val(u))
-
-Get a slice of a tuple in a type stable way.
-Equivalent to `t[l:u]` but type stable.
-"""
-function slice_tuple(t,::Val{L},::Val{U}) where {L,U}
-    return ntuple(i->t[i+L-1], U-L+1)
-end
-
-"""
-    split_tuple(t::Tuple{...}, ::Val{M}) where {N,M}
-
-Split the tuple `t` into two parts. the first part is `M` long.
-E.g
-```julia
-split_tuple((1,2,3,4),Val(3)) -> (1,2,3), (4,)
-```
-"""
-function split_tuple(t::NTuple{N,Any},::Val{M}) where {N,M}
-    return slice_tuple(t,Val(1), Val(M)), slice_tuple(t,Val(M+1), Val(N))
-end
-
-"""
-    split_tuple(t::Tuple{...},::Val{M},::Val{K}) where {N,M,K}
-
-Same as `split_tuple(t::NTuple{N},::Val{M})` but splits the tuple in three parts. With the first
-two parts having lenght `M` and `K`.
-"""
-function split_tuple(t::NTuple{N,Any},::Val{M},::Val{K}) where {N,M,K}
-    p1, tail = split_tuple(t, Val(M))
-    p2, p3 = split_tuple(tail, Val(K))
-    return p1,p2,p3
-end
-
-# TBD Are the above defs even needed? Can the below one be used without problems?
 
 """
     split_tuple(t, szs)