Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mtfishman opened this issue Mar 21, 2024 · 3 comments
Open

Comments

@mtfishman
Copy link
Contributor

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))))
@mtfishman
Copy link
Contributor Author

I raised an issue here: JuliaLang/julia#53806

@dlfivefifty
Copy link
Member

dlfivefifty commented Mar 25, 2024

Using this might be a work around: https://github.com/putianyi889/EltypeExtensions.jl

cf #352

@jishnub
Copy link
Member

jishnub commented Mar 25, 2024

On a longer term, I think JuliaLang/julia#48894 should fix many of these issues. I'll try to push that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants