StructArrays.jl
StructArrays.jl copied to clipboard
dims keyword constructor gives unintuitive result when types do not match
MWE:
julia> using StructArrays
julia> v = [1 3; 2 -1]
2×2 Matrix{Int64}:
1 3
2 -1
julia> StructArray{ComplexF64}(v, dims=1)
0-element StructArray(StructArray(), StructArray()) with eltype ComplexF64 with indices 1:0
It is probably best to error if types do not match.
Here's another concerning case:
julia> a = collect(reshape(1:9, 3, 3))
3×3 Matrix{Int64}:
1 4 7
2 5 8
3 6 9
julia> soa = StructArray{Complex{Int}}(a; dims=1)
3-element StructArray(view(::Matrix{Int64}, 1, :), view(::Matrix{Int64}, 2, :)) with eltype Complex{Int64}:
1 + 2im
4 + 5im
7 + 8im
I would have expected an error rather than just silently dropping the extra rows of a.
CC: @simonbyrne, who I think wrote the implementation of the dims method.