StructArrays.jl icon indicating copy to clipboard operation
StructArrays.jl copied to clipboard

dims keyword constructor gives unintuitive result when types do not match

Open piever opened this issue 4 years ago • 2 comments

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.

piever avatar Aug 26 '21 12:08 piever

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.

timholy avatar May 11 '22 08:05 timholy

CC: @simonbyrne, who I think wrote the implementation of the dims method.

piever avatar May 12 '22 13:05 piever