Skip to content

Commit

Permalink
Compatible parent index when displaying dots in SubArrays (#52097)
Browse files Browse the repository at this point in the history
Fix #52095 by passing the `reindex`ed indices through `to_indices` to
convert them to `Integer`s. This should strip `CartesianIndex`es in
particular, which resolves the issue.

Fixes:
```julia
julia> view(1:2, [CartesianIndex(2)])
1-element view(::UnitRange{Int64}, CartesianIndex{1}[CartesianIndex(2,)]) with eltype Int64:
 2
```
  • Loading branch information
jishnub authored Nov 16, 2023
1 parent 2fb06a7 commit 4689850
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/subarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,8 @@ end
has_offset_axes(S::SubArray) = has_offset_axes(S.indices...)

function replace_in_print_matrix(S::SubArray{<:Any,2,<:AbstractMatrix}, i::Integer, j::Integer, s::AbstractString)
replace_in_print_matrix(S.parent, reindex(S.indices, (i,j))..., s)
replace_in_print_matrix(S.parent, to_indices(S.parent, reindex(S.indices, (i,j)))..., s)
end
function replace_in_print_matrix(S::SubArray{<:Any,1,<:AbstractVector}, i::Integer, j::Integer, s::AbstractString)
replace_in_print_matrix(S.parent, reindex(S.indices, (i,))..., j, s)
replace_in_print_matrix(S.parent, to_indices(S.parent, reindex(S.indices, (i,)))..., j, s)
end
3 changes: 3 additions & 0 deletions test/subarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,9 @@ end
end
V = view(OneElVec(6, 2), 1:5)
@test sprint(show, "text/plain", V) == "$(summary(V)):\n\n 1\n\n\n"

V = view(1:2, [CartesianIndex(2)])
@test sprint(show, "text/plain", V) == "$(summary(V)):\n 2"
end

@testset "Base.first_index for offset indices" begin
Expand Down

0 comments on commit 4689850

Please sign in to comment.