Skip to content

empty(v::OffsetVector) returns a Vector #349

@matthias314

Description

@matthias314

The Julia documentation says that empty(v::AbstractVector) returns "an empty vector similar to v". Currently similar preserves indices for OffsetVector,

julia> v = OffsetVector([1,2], 0:1)
2-element OffsetArray(::Vector{Int64}, 0:1) with eltype Int64 with indices 0:1:
 1
 2

julia> similar(v)
2-element OffsetArray(::Vector{Int64}, 0:1) with eltype Int64 with indices 0:1:
 139997918114896
 139997785055648

but empty does not because it returns a Vector:

julia> empty(v)
Int64[]

Since empty reduces the length of the vector to zero, one can at most preserve either the first or the last index. Assuming that 0-based vectors are the most common use case for OffsetVector, I think it would make sense to preserve the first index in general.

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