Open m-wells opened 9 months ago
One point to note here is that the axes are not compliant with the interface requirements (although these weren't spelled out explicitly in prior Julia versions). Axes of arrays in Julia must be their own axes for consistency. Offset axes also need to respect this, so UnitRange
s are usually not valid axes but Base.IndentityUnitRange
s are. Does the issue still exist if you define the axes as map(x -> Base.IdentityUnitRange(x .- 1), axes(x.x))
? I haven't checked this, but this might resolve the issue
@jishnub While doing this does produce the desired output
julia> Base.axes(x::Foo) = map(x -> x .- 1, axes(x.x)); (k,)
julia> (x,)
([2, 3, 4, #undef],)
julia> Base.axes(x::Foo) = map(x -> Base.IdentityUnitRange(x .- 1), axes(x.x)); (k,)
julia> (x,)
([1, 2, 3, 4],)
You said
One point to note here is that the axes are not compliant with the interface requirements (although these weren't spelled out explicitly in prior Julia versions). Axes of arrays in Julia must be their own axes for consistency. Offset axes also need to respect this, so UnitRanges are usually not valid axes but Base.IndentityUnitRanges are.
but the documentation specifically uses the term UnitRange
as a valid type to return
If you're writing a non-1 indexed array type, you will want to specialize axes so it returns a UnitRange, or (perhaps better) a custom AbstractUnitRange. The advantage of a custom type is that it "signals" the allocation type for functions like similar. If we're writing an array type for which indexing will start at 0, we likely want to begin by creating a new AbstractUnitRange, ZeroRange, where ZeroRange(n) is equivalent to 0:n-1.
This should be updated. Using a UnitRange
will lead to many other bugs aside from the show
. See https://juliaarrays.github.io/OffsetArrays.jl/stable/internals/#Wrapping-other-offset-array-types
For non 1-based arrays that don't get limited (...) the output is incorrect. Example
Now if we go to a REPL
The issue is in
Base.show_vector
.https://github.com/JuliaLang/julia/blob/5b2fcb68800875e570d7bb8c78ed00d360b6cfd5/base/arrayshow.jl#L512-L532
And specifically due to https://github.com/JuliaLang/julia/blob/5b2fcb68800875e570d7bb8c78ed00d360b6cfd5/base/arrayshow.jl#L529-L531
A simple fix is