Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor tuple_of_arrays #144

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 5 additions & 44 deletions src/primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,51 +49,12 @@ julia> b,c = tuple_of_arrays(a)
```
"""
function tuple_of_arrays(a)
function first_and_tail(a)
x = map(first,a)
y = map(Base.tail,a)
x, y
if eltype(a) <: Tuple{}
return ()
end
function take(a,::Type{Tuple{T}} where T)
x = map(first,a)
(x,)
end
function take(a,::Type{Tuple{A,B}} where {A,B})
x, y = first_and_tail(a)
t1, = tuple_of_arrays(y)
(x,t1)
end
function take(a,::Type{Tuple{A,B,C}} where {A,B,C})
x, y = first_and_tail(a)
t1,t2 = tuple_of_arrays(y)
(x,t1,t2)
end
function take(a, ::Type{Tuple{A,B,C,D}} where {A,B,C,D})
x, y = first_and_tail(a)
t1, t2, t3 = tuple_of_arrays(y)
(x, t1, t2, t3)
end
function take(a, ::Type{Tuple{A,B,C,D,E}} where {A,B,C,D,E})
x, y = first_and_tail(a)
t1, t2, t3, t4 = tuple_of_arrays(y)
(x, t1, t2, t3, t4)
end
function take(a, ::Type{Tuple{A,B,C,D,E,F}} where {A,B,C,D,E,F})
x, y = first_and_tail(a)
t1, t2, t3, t4, t5 = tuple_of_arrays(y)
(x, t1, t2, t3, t4, t5)
end
function take(a, ::Type{Tuple{A,B,C,D,E,F,G}} where {A,B,C,D,E,F,G})
x, y = first_and_tail(a)
t1, t2, t3, t4, t5, t6 = tuple_of_arrays(y)
(x, t1, t2, t3, t4, t5, t6)
end
# this one is type instable, why? Previous methods for take are for circumvent this issue.
function take(a,::Type)
x, y = first_and_tail(a)
(x,tuple_of_arrays(y)...)
end
take(a,eltype(a))
x = map(first, a)
y = map(Base.tail, a)
return (x, tuple_of_arrays(y)...)
end


Expand Down
Loading