File tree Expand file tree Collapse file tree 2 files changed +44
-4
lines changed Expand file tree Collapse file tree 2 files changed +44
-4
lines changed Original file line number Diff line number Diff line change @@ -574,6 +574,16 @@ Base.copyto!(dest::SubOrDArray, src::SubOrDArray) = begin
574
574
end
575
575
Base. copy! (dest:: SubOrDArray , src:: SubOrDArray ) = copyto! (dest, src)
576
576
577
+ function Base. deepcopy (src:: DArray )
578
+ dest = similar (src)
579
+ asyncmap (procs (src)) do p
580
+ remotecall_fetch (p) do
581
+ dest[:L ] = deepcopy (src[:L ])
582
+ end
583
+ end
584
+ return dest
585
+ end
586
+
577
587
# local copies are obtained by convert(Array, ) or assigning from
578
588
# a SubDArray to a local Array.
579
589
Original file line number Diff line number Diff line change 60
60
61
61
check_leaks ()
62
62
63
- @testset " test DArray equality" begin
63
+ @testset " test DArray equality/copy/deepcopy " begin
64
64
D = drand ((200 ,200 ), [MYID, OTHERIDS])
65
- DC = copy (D)
66
65
67
66
@testset " test isequal(::DArray, ::DArray)" begin
67
+ DC = copy (D)
68
68
@test D == DC
69
+ close (DC)
69
70
end
70
71
71
- @testset " test copy(::DArray) does a copy of each localpart" begin
72
+ @testset " test [deep]copy(::DArray) does a copy of each localpart" begin
73
+ DC = copy (D)
72
74
@spawnat OTHERIDS localpart (DC)[1 ] = 0
73
75
@test fetch (@spawnat OTHERIDS localpart (D)[1 ] != 0 )
76
+ DD = deepcopy (D)
77
+ @spawnat OTHERIDS localpart (DD)[1 ] = 0
78
+ @test fetch (@spawnat OTHERIDS localpart (D)[1 ] != 0 )
79
+ close (DC)
80
+ close (DD)
81
+ end
82
+
83
+ @testset " test copy(::DArray) is shallow" begin
84
+ DA = @DArray [rand (100 ) for i= 1 : 10 ]
85
+ DC = copy (DA)
86
+ id = procs (DC)[1 ]
87
+ @test DA == DC
88
+ fetch (@spawnat id localpart (DC)[1 ] .= - 1.0 )
89
+ @test DA == DC
90
+ @test fetch (@spawnat id all (localpart (DA)[1 ] .== - 1.0 ))
91
+ close (DA)
92
+ close (DC)
93
+ end
94
+
95
+ @testset " test deepcopy(::DArray) is not shallow" begin
96
+ DA = @DArray [rand (100 ) for i= 1 : 10 ]
97
+ DC = deepcopy (DA)
98
+ id = procs (DC)[1 ]
99
+ @test DA == DC
100
+ fetch (@spawnat id localpart (DC)[1 ] .= - 1.0 )
101
+ @test DA != DC
102
+ @test fetch (@spawnat id all (localpart (DA)[1 ] .>= 0.0 ))
103
+ close (DA)
104
+ close (DC)
74
105
end
75
106
76
107
close (D)
77
- close (DC)
78
108
end
79
109
80
110
check_leaks ()
You can’t perform that action at this time.
0 commit comments