Skip to content

Commit 507b05d

Browse files
committed
Improve implementation of split_tuple
Add util functions front_tuple and back_tuple
1 parent d5d6968 commit 507b05d

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/util.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@ end
1717
Base.@pure _ncolons(::Val{N}) where N = ntuple(_ -> Colon(), Val{N}())
1818

1919

20-
@inline function _split_tuple_impl(x::NTuple{N,Any}, y::Tuple, ::Val{N}) where {N}
21-
x, y
22-
end
20+
Base.@propagate_inbounds front_tuple(x::NTuple{N}, ::Val{M}) where {N,M} =
21+
Base.ntuple(i -> x[i], Val{M}())
2322

24-
@inline function _split_tuple_impl(x::NTuple{M,Any}, y::Tuple, ::Val{N}) where {M, N}
25-
_split_tuple_impl((x..., y[1]), _tail(y), Val{N}())
26-
end
23+
Base.@propagate_inbounds back_tuple(x::NTuple{N}, ::Val{M}) where {N,M} =
24+
Base.ntuple(i -> x[i + N - M], Val{M}())
2725

28-
@inline split_tuple(x, ::Val{N}) where {N} = _split_tuple_impl((), x, Val{N}())
26+
Base.@propagate_inbounds split_tuple(x::NTuple{N}, ::Val{M}) where {N,M} =
27+
(front_tuple(x, Val{M}()), back_tuple(x, Val{N - M}()))
2928

3029

3130
_convert_elype(::Type{T}, A::AbstractArray{T}) where {T} = A

0 commit comments

Comments
 (0)