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

broadcast type preservation #674

Open
wants to merge 1 commit into
base: main
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
6 changes: 3 additions & 3 deletions src/unzipped.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function unzip_broadcast(f::F, args...) where {F}
# This is a crude way to allow GPU arrays, not currently tested, TODO.
# See also https://github.com/JuliaArrays/StructArrays.jl/issues/150
return unzip(broadcast(f, args...))
elseif bcs isa Broadcast.AbstractArrayStyle
elseif bcs isa Broadcast.Broadcast.ArrayStyle{<:Array} # components of a structarray is array, so it has to broadcast to an array
return StructArrays.components(StructArray(bc))
else
return unzip(broadcast(f, args...)) # e.g. tuples
Expand Down Expand Up @@ -103,7 +103,7 @@ function unzip(xs::AbstractArray)
end

@generated function unzip(xs, ::Val{N}) where {N}
each = [:(map($(Get(i)), xs)) for i in 1:N]
each = [:(broadcast($(Get(i)), xs)) for i in 1:N]
Expr(:tuple, each...)
end

Expand All @@ -114,7 +114,7 @@ unzip(xs::AbstractArray{Tuple{T}}) where {T} = (reinterpret(T, xs),) # best cas
# good case, no copy of data, some trivial arrays
[Base.issingletontype(T) ? :(similar(xs, $T)) : :(reinterpret($T, xs)) for T in Ts.parameters]
else
[:(map($(Get(i)), xs)) for i in 1:length(fieldnames(Ts))]
[:(broadcast($(Get(i)), xs)) for i in 1:length(fieldnames(Ts))]
end
Expr(:tuple, each...)
end
Expand Down