Skip to content

Return Vector when creating similar VectorOfArray with new length #401

Description

@ErikQQY

Question❓

Not sure if it's intended to behave like this or just a bug. When creating a similar array of VectorOfArray with a new length, wouldn't it be more intuitive to get VectorOfArray instead of just Vector? Since when we are doing the same for Vector{Vector}, we would end up getting Vector{Vector}.

julia> a = [rand(2) for _ in 1:3]
3-element Vector{Vector{Float64}}:
 [0.22672429007808392, 0.006545325869979246]
 [0.45202853665794596, 0.007153478061376006]
 [0.01950886804209273, 0.7556357057552318]

julia> va = VectorOfArray(a)
VectorOfArray{Float64,2}:
3-element Vector{Vector{Float64}}:
 [0.22672429007808392, 0.006545325869979246]
 [0.45202853665794596, 0.007153478061376006]
 [0.01950886804209273, 0.7556357057552318]

julia> similar(va, 4)
4-element Vector{Float64}:
 4.0e-323
 6.95219884198975e-310
 6.9522006963596e-310
 6.9521976152192e-310

julia> similar(a, 4)
4-element Vector{Vector{Float64}}:
 #undef
 #undef
 #undef
 #undef

Activity

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions