Skip to content

Commit fb39bdb

Browse files
authored
Preserve input type for unaliascopy(::ReinterpretArray) (#39316)
1 parent a91131f commit fb39bdb

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

base/reinterpretarray.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ eachindex(style::IndexSCartesian2, A::AbstractArray) = eachindex(style, parent(A
278278

279279
parent(a::ReinterpretArray) = a.parent
280280
dataids(a::ReinterpretArray) = dataids(a.parent)
281-
unaliascopy(a::ReinterpretArray{T}) where {T} = reinterpret(T, unaliascopy(a.parent))
281+
unaliascopy(a::NonReshapedReinterpretArray{T}) where {T} = reinterpret(T, unaliascopy(a.parent))
282+
unaliascopy(a::ReshapedReinterpretArray{T}) where {T} = reinterpret(reshape, T, unaliascopy(a.parent))
282283

283284
function size(a::NonReshapedReinterpretArray{T,N,S} where {N}) where {T,S}
284285
psize = size(a.parent)

test/reinterpretarray.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,3 +368,11 @@ ars = reinterpret(reshape, Int, a)
368368
@test as isa TSlow{NTuple{4,Float64},1}
369369
@test size(as) == (4,)
370370
end
371+
372+
373+
@testset "aliasing" begin
374+
a = reinterpret(NTuple{2,Float64}, rand(Float64, 4, 4))
375+
@test typeof(Base.unaliascopy(a)) === typeof(a)
376+
a = reinterpret(reshape, NTuple{4,Float64}, rand(Float64, 4, 4))
377+
@test typeof(Base.unaliascopy(a)) === typeof(a)
378+
end

0 commit comments

Comments
 (0)