Skip to content

Commit

Permalink
Preserve input type for unaliascopy(::ReinterpretArray) (JuliaLang#39316
Browse files Browse the repository at this point in the history
)
  • Loading branch information
timholy committed Jan 19, 2021
1 parent a91131f commit fb39bdb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion base/reinterpretarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ eachindex(style::IndexSCartesian2, A::AbstractArray) = eachindex(style, parent(A

parent(a::ReinterpretArray) = a.parent
dataids(a::ReinterpretArray) = dataids(a.parent)
unaliascopy(a::ReinterpretArray{T}) where {T} = reinterpret(T, unaliascopy(a.parent))
unaliascopy(a::NonReshapedReinterpretArray{T}) where {T} = reinterpret(T, unaliascopy(a.parent))
unaliascopy(a::ReshapedReinterpretArray{T}) where {T} = reinterpret(reshape, T, unaliascopy(a.parent))

function size(a::NonReshapedReinterpretArray{T,N,S} where {N}) where {T,S}
psize = size(a.parent)
Expand Down
8 changes: 8 additions & 0 deletions test/reinterpretarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,11 @@ ars = reinterpret(reshape, Int, a)
@test as isa TSlow{NTuple{4,Float64},1}
@test size(as) == (4,)
end


@testset "aliasing" begin
a = reinterpret(NTuple{2,Float64}, rand(Float64, 4, 4))
@test typeof(Base.unaliascopy(a)) === typeof(a)
a = reinterpret(reshape, NTuple{4,Float64}, rand(Float64, 4, 4))
@test typeof(Base.unaliascopy(a)) === typeof(a)
end

0 comments on commit fb39bdb

Please sign in to comment.