Skip to content

dims keyword constructor gives unintuitive result when types do not match #200

Open

Description

@piever

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.

Activity

  1. timholy commented on May 11, 2022

    @timholy
    Member

    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.

  2. piever commented on May 12, 2022

    @piever
    CollaboratorAuthor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions