Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion base/reinterpretarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,10 @@ end
# `IndexStyle(a) == IndexLinear()`, it's advantageous to retain pseudo-linear indexing.
struct IndexSCartesian2{K} <: IndexStyle end # K = aligned_sizeof(S) ÷ aligned_sizeof(T), a static-sized 2d cartesian iterator

IndexStyle(::Type{ReinterpretArray{T,N,S,A,false}}) where {T,N,S,A<:AbstractArray{S,N}} = IndexStyle(A)
# only `IndexLinear` is known to be valid when the axes change (#63305)
IndexStyle(::Type{ReinterpretArray{T,N,S,A,false}}) where {T,N,S,A<:AbstractArray{S,N}} =
IndexStyle(A) === IndexLinear() ? IndexLinear() : IndexCartesian()

function IndexStyle(::Type{ReinterpretArray{T,N,S,A,true}}) where {T,N,S,A<:AbstractArray{S}}
if aligned_sizeof(T) < aligned_sizeof(S)
IndexStyle(A) === IndexLinear() && return IndexSCartesian2{aligned_sizeof(S) ÷ aligned_sizeof(T)}()
Expand Down
8 changes: 8 additions & 0 deletions test/reinterpretarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -880,3 +880,11 @@ end
@test !Base.array_subpadding(T_5, S_1_3)
@test !Base.array_subpadding(S_1_3, T_5)
end

@testset "issue #63305" begin
a = ones(UInt64, 2)
b = reinterpret(UInt8, reinterpret(reshape, UInt16, a))
c = collect(b)
@test c[5] == b[5] == 0x00
@test vec(c) == reinterpret(UInt8, a)
end
Loading