JuliaArrays / JuliaArrays/OffsetArrays.jl

`empty(v::OffsetVector)` returns a `Vector`

Open
#349 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
212
Forks
45
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the OffsetVector implementations or methods for empty(v) and similar(v), then inspect any existing tests covering these operations. Reproduce the examples from the issue and verify that the completed change preserves the first index while returning an empty OffsetVector rather than a Vector.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.