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

diff on some ranges now error #36116

Closed
KristofferC opened this issue Jun 2, 2020 · 2 comments
Closed

diff on some ranges now error #36116

KristofferC opened this issue Jun 2, 2020 · 2 comments
Labels
regression Regression in behavior compared to a previous version
Milestone

Comments

@KristofferC
Copy link
Member

julia> diff(0:2)
ERROR: ArgumentError: step cannot be zero
Stacktrace:
 [1] steprange_last(::Int64, ::Int64, ::Int64) at ./range.jl:215
 [2] StepRange at ./range.jl:205 [inlined]
 [3] _rangestyle at ./range.jl:118 [inlined]
 [4] _range at ./range.jl:116 [inlined]
 [5] #range#43 at ./range.jl:91 [inlined]
 [6] -(::UnitRange{Int64}, ::UnitRange{Int64}) at ./range.jl:1044
 [7] broadcasted at ./broadcast.jl:1081 [inlined]
 [8] broadcasted at ./broadcast.jl:1263 [inlined]
 [9] diff(::UnitRange{Int64}; dims::Int64) at ./multidimensional.jl:849
 [10] diff(::UnitRange{Int64}) at ./multidimensional.jl:809
 [11] top-level scope at REPL[3]:1

julia> diff(collect(0:2))
2-element Array{Int64,1}:
 1
 1

In 1.4, both of these gave a consistent answer.

From PkgEval for 1.5 (https://github.com/JuliaCI/NanosoldierReports/blob/90885ffd4005a91d0dc4150b8c1453f2f5948eb0/pkgeval/by_hash/194ddda_vs_b5f13c3/logs/ContinuumArrays/1.5.0-DEV-f11a73bd9c.log).

@KristofferC KristofferC added this to the 1.5 milestone Jun 2, 2020
@KristofferC
Copy link
Member Author

Probably caused by #26872. cc @andyferris

@JeffBezanson JeffBezanson added the regression Regression in behavior compared to a previous version label Jun 2, 2020
@mbauman
Copy link
Member

mbauman commented Jun 2, 2020

Yup, it's effectively doing:

r = 0:2
@views r[1:end-1] .- r[2:end]

... which of course hits #10391. Seems like a cute place for a range-based specialization (fill(step(r), length(r)-1)), but I suppose we should just preserve the way it was and return actual values.

KristofferC pushed a commit that referenced this issue Jun 4, 2020
* fix #36116, diff(::AbstractRange) returns an Array

(cherry picked from commit b49a0d5)
simeonschaub pushed a commit to simeonschaub/julia that referenced this issue Aug 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression Regression in behavior compared to a previous version
Projects
None yet
Development

No branches or pull requests

3 participants