Skip to content

Should the Origin constructor call no_offset_view first? #279

@jishnub

Description

@jishnub

This seems to lead to some overflow bugs otherwise, which might be avoided by a more careful offset calculation, or more simply by just calling no_offset_view on the argument before passing it to the constructor.

julia> A = Origin(typemin(Int)+1)(rand(3,3))
3×3 OffsetArray(::Matrix{Float64}, -9223372036854775807:-9223372036854775805, -9223372036854775807:-9223372036854775805) with eltype Float64 with indices -9223372036854775807:-9223372036854775805×-9223372036854775807:-9223372036854775805:
 0.31876   0.827393   0.132595
 0.764406  0.364263   0.83437
 0.733822  0.0985983  0.309434

julia> Origin(typemax(Int)-4)(A)
ERROR: OverflowError: offset should be >= -1 corresponding to the axis OffsetArrays.IdOffsetRange(values=-9223372036854775807:-9223372036854775805, indices=-9223372036854775807:-9223372036854775805), received an offset -6
Stacktrace:
 [1] (::OffsetArrays.var"#throw_lower_overflow_error#8"{OffsetArrays.IdOffsetRange{Int64, Base.OneTo{Int64}}, Int64})(val::Int64)
   @ OffsetArrays ~/.julia/packages/OffsetArrays/N7ji6/src/OffsetArrays.jl:141
 [2] overflow_check
   @ ~/.julia/packages/OffsetArrays/N7ji6/src/OffsetArrays.jl:150 [inlined]
 [3] map
   @ ./tuple.jl:299 [inlined]
 [4] #OffsetArray#14
   @ ~/.julia/packages/OffsetArrays/N7ji6/src/OffsetArrays.jl:182 [inlined]
 [5] #OffsetArray#21
   @ ~/.julia/packages/OffsetArrays/N7ji6/src/OffsetArrays.jl:210 [inlined]
 [6] OffsetArray
   @ ~/.julia/packages/OffsetArrays/N7ji6/src/OffsetArrays.jl:210 [inlined]
 [7] (::Origin{Int64})(A::OffsetMatrix{Float64, Matrix{Float64}})
   @ OffsetArrays ~/.julia/packages/OffsetArrays/N7ji6/src/OffsetArrays.jl:213
 [8] top-level scope
   @ REPL[15]:1

julia> Origin(typemax(Int)-4)(OffsetArrays.no_offset_view(A))
3×3 OffsetArray(::Matrix{Float64}, 9223372036854775803:9223372036854775805, 9223372036854775803:9223372036854775805) with eltype Float64 with indices 9223372036854775803:9223372036854775805×9223372036854775803:9223372036854775805:
 0.31876   0.827393   0.132595
 0.764406  0.364263   0.83437
 0.733822  0.0985983  0.309434

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