Skip to content

Commit

Permalink
ReinterpretArray: avoid nesting (JuliaLang#34625)
Browse files Browse the repository at this point in the history
  • Loading branch information
stev47 committed Feb 3, 2020
1 parent c3f6542 commit af17bb6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions base/reinterpretarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ struct ReinterpretArray{T,N,S,A<:AbstractArray{S, N}} <: AbstractArray{T, N}
end
end

reinterpret(::Type{T}, a::ReinterpretArray) where {T} = reinterpret(T, a.parent)

# Definition of StridedArray
StridedFastContiguousSubArray{T,N,A<:DenseArray} = FastContiguousSubArray{T,N,A}
StridedReinterpretArray{T,N,A<:Union{DenseArray,StridedFastContiguousSubArray}} = ReinterpretArray{T,N,S,A} where S
Expand Down
3 changes: 3 additions & 0 deletions test/reinterpretarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ end
@test x1[] === x2[] === Int64(2)
end

# avoid nesting
@test parent(reinterpret(eltype(A), reinterpret(eltype(B), A))) === A

# Test 0-dimensional Arrays
A = zeros(UInt32)
B = reinterpret(Int32,A)
Expand Down

0 comments on commit af17bb6

Please sign in to comment.