Skip to content

Commit 313be3a

Browse files
committed
add aliasing test
1 parent 61d63b0 commit 313be3a

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

test/core/aliasing.jl

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using Reactant, Test
2+
3+
function buffer_equals(x, y)
4+
if x isa Reactant.ConcreteIFRTArray
5+
y.data.buffer == x.data.buffer
6+
elseif x isa Reactant.ConcretePJRTArray
7+
y.data.buffers == x.data.buffers
8+
else
9+
error("invalid array type $(typeof(x))")
10+
end
11+
end
12+
13+
function copy_with_broadcast!(a, b)
14+
a .= b
15+
return nothing
16+
end
17+
18+
mutable struct X{T}
19+
x::T
20+
y::T
21+
end
22+
23+
function br_func!(x, z)
24+
x.x .= z
25+
x.y = x.x
26+
return nothing
27+
end
28+
29+
@testset "Buffer aliasing" begin
30+
x = Reactant.to_rarray(ones(10))
31+
y = similar(x)
32+
@jit copy_with_broadcast!(y, x)
33+
@test !buffer_equals(x, y)
34+
35+
x = Reactant.to_rarray(ones(10))
36+
y = Reactant.to_rarray(ones(10))
37+
x = X(x, y)
38+
z = Reactant.to_rarray(ones(10))
39+
@jit br_func!(x, z)
40+
@test buffer_equals(x.x, x.y)
41+
@test !buffer_equals(x.x, z)
42+
end

0 commit comments

Comments
 (0)