Another issue with my migration to StructArrays
. There is one problem I don’t understand when trying to broadcast a function that gets a property and this property, specifically, is of type String
. For example:
julia> struct A
s::String
i::Int
end
julia> get_s(a::A) = a.s
get_s (generic function with 1 method)
julia> get_i(a::A) = a.i
get_i (generic function with 1 method)
julia> v1 = [ A("a",1), A("b",2) ]
2-element Vector{A}:
A("a", 1)
A("b", 2)
julia> using StructArrays
julia> v2 = StructArray(v1)
2-element StructArray(::Vector{String}, ::Vector{Int64}) with eltype A:
A("a", 1)
A("b", 2)
julia> get_s.(v2)
ERROR: DimensionMismatch("destination axes (1:0,) are not compatible with source axes (Base.OneTo(2),)")
Stacktrace:
[1] throwdm(axdest::Tuple{UnitRange{Int64}}, axsrc::Tuple{Base.OneTo{Int64}})
@ Base.Broadcast ./broadcast.jl:1060
[2] copyto!
@ ./broadcast.jl:972 [inlined]
[3] copyto!
@ ./broadcast.jl:936 [inlined]
[4] copy
@ ./broadcast.jl:908 [inlined]
[5] materialize(bc::Base.Broadcast.Broadcasted{StructArrays.StructArrayStyle{Base.Broadcast.DefaultArrayStyle{1}}, Nothing, typeof(get_s), Tuple{StructVector{A, NamedTuple{(:s, :i), Tuple{Vector{String}, Vector{Int64}}}, Int64}}})
@ Base.Broadcast ./broadcast.jl:883
[6] top-level scope
@ REPL[9]:1
Probably no need to demonstrate, but all other broadcasting operations and get calls work:
julia> get_s(v2[1])
"a"
julia> get_i.(v2)
2-element Vector{Int64}:
1
2
julia> get_s.(v1)
2-element Vector{String}:
"a"
"b"
julia> get_i.(v1)
2-element Vector{Int64}:
1
2