Skip to content

cumsum for Ones has inconsistent output type depending on element type #353

Description

@mtfishman

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))))

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions