JuliaArrays / JuliaArrays/FillArrays.jl

`cumsum` for `Ones` has inconsistent output type depending on element type

Open
#353 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
187
Forks
41
Avg merge
17h 29m
Merged PRs (30d)
1

Description

For example using FillArrays v1.9.3:

julia> using FillArrays

julia> cumsum(Ones{Int64}(4))
Base.OneTo(4)

julia> cumsum(Ones{Int32}(4))
4-element Vector{Int32}:
 1
 2
 3
 4

I believe the issue is this line: https://github.com/JuliaArrays/FillArrays.jl/blob/v1.9.3/src/FillArrays.jl#L578.

It may in fact be an issue with convert of Base.OneTo:

julia> convert(AbstractVector{Int64}, Base.OneTo(4))
Base.OneTo(4)

julia> convert(AbstractVector{Int32}, Base.OneTo(4))
4-element Vector{Int32}:
 1
 2
 3
 4

i.e. it seems like it should preserve that it is Base.OneTo and just change the element type. A workaround could be to use:

cumsum(x::AbstractOnesVector{II}) where II<:Integer = convert(AbstractVector{II}, oneto(II(length(x))))

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

Reproduce the two cumsum examples from the issue, then inspect src/FillArrays.jl around line 578 and Julia's conversion of Base.OneTo to AbstractVector. Verify the intended behavior for Int64 and Int32 and add or update coverage so the result preserves the appropriate lazy range representation.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.