File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments