Skip to content

Commit

Permalink
Specialize 2-arg show for LinearIndices (#56482)
Browse files Browse the repository at this point in the history
After this,
```julia
julia> l = LinearIndices((1:3, 1:4));

julia> show(l)
LinearIndices((1:3, 1:4))
```
The printed form is a valid constructor.
  • Loading branch information
jishnub authored Nov 8, 2024
1 parent bfcd3e9 commit 9c4541b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions base/indices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -576,3 +576,7 @@ first(iter::LinearIndices) = 1
first(iter::LinearIndices{1}) = (@inline; first(axes1(iter.indices[1])))
last(iter::LinearIndices) = (@inline; length(iter))
last(iter::LinearIndices{1}) = (@inline; last(axes1(iter.indices[1])))

function show(io::IO, iter::LinearIndices)
print(io, "LinearIndices(", iter.indices, ")")
end
9 changes: 9 additions & 0 deletions test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,15 @@ end
R = LinearIndices((Base.IdentityUnitRange(0:1), 0:1))
@test axes(R) == (Base.IdentityUnitRange(0:1), Base.OneTo(2))
end

@testset "show" begin
A = zeros(2,3)
for B in (A, view(A, Base.IdentityUnitRange(2:4)))
l = LinearIndices(B)
s = sprint(show, l)
@test s == "LinearIndices($(axes(B)))"
end
end
end

@testset "copy for LinearIndices/CartesianIndices" begin
Expand Down

0 comments on commit 9c4541b

Please sign in to comment.