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! does not check array sizes #18363

Closed
stevengj opened this issue Sep 5, 2016 · 7 comments
Closed

cumsum! does not check array sizes #18363

stevengj opened this issue Sep 5, 2016 · 7 comments
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@stevengj
Copy link
Member

stevengj commented Sep 5, 2016

julia> cumsum!([0,0], 1:4)

signal (11): Segmentation fault: 11
@stevengj stevengj added the bug Indicates an unexpected problem or unintended behavior label Sep 5, 2016
@stevengj
Copy link
Member Author

stevengj commented Sep 5, 2016

Also, it looks like the code assumes 1-based indexing; PR forthcoming that should fix both this and #18336.

@stevengj
Copy link
Member Author

stevengj commented Sep 5, 2016

Another problem:

julia> cumsum(Any[])
ERROR: BoundsError: attempt to access 0-element Array{Any,1} at index [1]
 in cumsum(::Array{Any,1}) at ./arraymath.jl:448

which comes because the _cumsum_type(v) = typeof(v[1]+v[1]) definition is wrong. Grr.

@stevengj
Copy link
Member Author

stevengj commented Sep 5, 2016

And cumsum(Any[1, 2.3]) throws an InexactError. I think _cumsum_type is just wrong and we should use similar(v) in all cases.

@andreasnoack
Copy link
Member

Bools are not stable under addition.

@stevengj
Copy link
Member Author

stevengj commented Sep 5, 2016

Oh, right.

@nalimilan
Copy link
Member

promote_type(+, ...)?

@stevengj
Copy link
Member Author

stevengj commented Sep 5, 2016

We already have an r_promote that is used for reductions; it seems better to be be consistent with that. In any case, please move this discussion to #18364.

@timholy timholy closed this as completed in a0f30e6 Sep 8, 2016
timholy added a commit that referenced this issue Sep 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants