@@ -17,6 +17,28 @@ for runtime in (:PJRT, :IFRT)
17
17
end
18
18
end
19
19
20
+ # copy
21
+ function Base. copy (x:: Union{AbstractConcreteArray,AbstractConcreteNumber} )
22
+ fn = Reactant. compile (copy, (x,))
23
+ return fn (x)
24
+ end
25
+
26
+ # deepcopy
27
+ function Base. deepcopy (x:: Union{AbstractConcreteArray,AbstractConcreteNumber} )
28
+ fn = Reactant. compile (copy, (x,))
29
+ return fn (x)
30
+ end
31
+
32
+ # One more reason why users shouldn't call `deepcopy`
33
+ function Base. deepcopy_internal (
34
+ x:: Union{AbstractConcreteArray,AbstractConcreteNumber} , stackdict:: IdDict
35
+ )
36
+ if haskey (stackdict, x)
37
+ return stackdict[x]:: typeof (x)
38
+ end
39
+ return deepcopy (x)
40
+ end
41
+
20
42
Base. size (:: AbstractConcreteNumber ) = ()
21
43
Base. real (x:: AbstractConcreteNumber{<:Real} ) = x
22
44
function Base. rtoldefault (T:: Type{<:AbstractConcreteNumber} )
@@ -410,14 +432,10 @@ end
410
432
411
433
for aType in (:ConcretePJRTArray , :ConcreteIFRTArray )
412
434
@eval function Base. copyto! (dest:: $ (aType), src:: $ (aType))
413
- if dest. sharding == src. sharding &&
414
- XLA. device (dest) == XLA. device (src) &&
415
- XLA. client (dest) == XLA. client (src)
416
- dest. data = src. data
417
- else
418
- fn = compile (mycopyto!, (dest, src))
419
- fn (dest, src)
420
- end
435
+ # We can't directly set the data field. it will alias the inner buffers without
436
+ # actually copying them.
437
+ fn = compile (mycopyto!, (dest, src))
438
+ fn (dest, src)
421
439
return dest
422
440
end
423
441
end
0 commit comments