Skip to content

Commit

Permalink
Fix 29545: Implement unaliascopy for ReinterpretArray (JuliaLang#30296)
Browse files Browse the repository at this point in the history
* Fix 29545: Implement unaliascopy for ReinterpretArray
  • Loading branch information
mbauman committed Mar 20, 2019
1 parent b207c01 commit f611b46
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/reinterpretarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ IndexStyle(a::ReinterpretArray) = IndexStyle(a.parent)

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

function size(a::ReinterpretArray{T,N,S} where {N}) where {T,S}
psize = size(a.parent)
Expand Down
10 changes: 10 additions & 0 deletions test/reinterpretarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,16 @@ let a = [0.1 0.2; 0.3 0.4], at = reshape([(i,i+1) for i = 1:2:8], 2, 2)
@test r == OffsetArray(reshape(1:8, 2, 2, 2), (0, offsetvt...))
end

@testset "potentially aliased copies" begin
buffer = UInt8[1,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0]
mid = length(buffer) ÷ 2
x1 = reinterpret(Int64, @view buffer[1:mid])
x2 = reinterpret(Int64, @view buffer[mid+1:end])
x1 .= x2
@test x1 == x2 == [2]
@test x1[] === x2[] === Int64(2)
end

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

0 comments on commit f611b46

Please sign in to comment.