Skip to content

Bugfix in overflow, CartesianIndices for BigInt ranges #227

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

Merged
merged 7 commits into from
Apr 11, 2021

Conversation

jishnub
Copy link
Member

@jishnub jishnub commented Mar 15, 2021

There was a bug introduced by #226 , this PR fixes that.

On master:

julia> OffsetVector(big(1):big(2), 0)
ERROR: MethodError: no method matching overflow_check(::Base.OneTo{BigInt}, ::Int64)

After this PR:

julia> OffsetVector(big(1):big(2), 0)
1:2 with indices 1:2

Also fixes a bug in CartesianIndices caused by a missing method for IdOffsetRange. This is broken on master anyway because of the previous bug, so we need to fix that to see this. After adding the fix:

julia> a = OffsetArray(big(1):big(2), 0);

julia> CartesianIndices(a)
ERROR: MethodError: no method matching AbstractUnitRange{Int64}(::OffsetArrays.IdOffsetRange{BigInt,Base.OneTo{BigInt}})

After this PR:

julia> CartesianIndices(a)
2-element CartesianIndices{1,Tuple{OffsetArrays.IdOffsetRange{Int64,Base.OneTo{Int64}}}} with indices 1:2:
 CartesianIndex(1,)
 CartesianIndex(2,)

@codecov
Copy link

codecov bot commented Mar 15, 2021

Codecov Report

Merging #227 (f9479f4) into master (b33bc00) will decrease coverage by 4.70%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #227      +/-   ##
==========================================
- Coverage   99.04%   94.33%   -4.71%     
==========================================
  Files           5        5              
  Lines         314      318       +4     
==========================================
- Hits          311      300      -11     
- Misses          3       18      +15     
Impacted Files Coverage Δ
src/OffsetArrays.jl 98.12% <100.00%> (-0.47%) ⬇️
src/axes.jl 100.00% <100.00%> (ø)
src/precompile.jl 0.00% <0.00%> (-100.00%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b33bc00...f9479f4. Read the comment docs.

@jishnub
Copy link
Member Author

jishnub commented Mar 15, 2021

Test failure on nightly is probably a breakage. JuliaLang/julia#40035

Can be fixed by defining the conversion of an IdOffsetRange to an OrdinalRange

@jishnub
Copy link
Member Author

jishnub commented Mar 16, 2021

4eebd90 fixes overflow checks to use the axes and not the offset (which is usually an Int). This means that we may skip overflow checks for BigInt axes.

Before:

julia> OffsetArray(1:big(2)^65, 4000)
ERROR: OverflowError: offset should be <= -27670116110564327425 corresponding to the axis Base.OneTo(36893488147419103232), received an offset 4000

Now:

julia> OffsetArray(1:big(2)^65, 4000)
1:36893488147419103232 with indices 4001:36893488147419107232

@jishnub
Copy link
Member Author

jishnub commented Mar 16, 2021

Whoops I committed the offsetranges.jl file by mistake

Copy link
Member

@johnnychen94 johnnychen94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand it correctly, except for the compat patch for JuliaLang/julia#40038, this PR is ready? So far it looks good to me.

@jishnub
Copy link
Member Author

jishnub commented Mar 17, 2021

Yes this is ready

src/axes.jl Outdated
AbstractUnitRange{T}(r::IdOffsetRange{T}) where T<:Integer = r
AbstractUnitRange{T}(r::IdOffsetRange) where T<:Integer = IdOffsetRange{T}(r)

OrdinalRange{T,T}(r::IdOffsetRange) where {T<:Integer} = AbstractUnitRange{T}(r)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps add a comment to JuliaLang/julia#40038 so that people know this can be removed in future Julia versions.

@jishnub jishnub merged commit 8b1a809 into JuliaArrays:master Apr 11, 2021
@jishnub jishnub deleted the overflowbugfix branch April 11, 2021 05:13
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

Successfully merging this pull request may close these issues.

2 participants