Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion src/structarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,9 @@ function Broadcast.broadcast_unalias(dest::StructArray, src::AbstractArray)
end
end

Base.dataids(u::StructArray) = mapreduce(Base.dataids, (a, b) -> (a..., b...), values(components(u)), init=())
Base.dataids(u::StructArray) = dataids_cols(components(u))
# generated to stay inferrable and non-allocating for any number of columns
@generated dataids_cols(cols::Tup) = :(Base.Cartesian.@ntuple $(fieldcount(cols)) i -> Base.dataids(cols[i])...)

# Since all the components have the same axes, we choose the type of the first one to
# define IteratorSize for a StructArray
Expand Down
12 changes: 12 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,18 @@ Base.BroadcastStyle(::Broadcast.ArrayStyle{MyArray2}, S::Broadcast.DefaultArrayS

# used inside of broadcast but we also test it here explicitly
@test isa(@inferred(Base.dataids(s)), NTuple{N, UInt} where {N})
@test Base.dataids(s) == (UInt(pointer(s.re)), UInt(pointer(s.im)))

# more columns than Base tuple functions handle inferrably
x, idx = rand(3), [3, 2, 1]
cols = (ntuple(_ -> rand(3), 31)..., 1:3, view(x, idx))
ids = (map(c -> UInt(pointer(c)), cols[1:31])..., UInt(pointer(x)), UInt(pointer(idx)))
sw = StructArray(NamedTuple{ntuple(i -> Symbol(:c, i), 33)}(cols))
@test @inferred(Base.dataids(sw)) == ids
@test @inferred(Base.dataids(StructArray(cols))) == ids
dataids_allocs(s) = @allocated Base.dataids(s)
dataids_allocs(sw)
@test dataids_allocs(sw) == 0


@testset "style conflict check" begin
Expand Down
Loading