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
574574end
575575Base. copy! (dest:: SubOrDArray , src:: SubOrDArray ) = copyto! (dest, src)
576576
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+
577587# local copies are obtained by convert(Array, ) or assigning from
578588# a SubDArray to a local Array.
579589
Original file line number Diff line number Diff line change 6060
6161check_leaks ()
6262
63- @testset " test DArray equality" begin
63+ @testset " test DArray equality/copy/deepcopy " begin
6464 D = drand ((200 ,200 ), [MYID, OTHERIDS])
65- DC = copy (D)
6665
6766 @testset " test isequal(::DArray, ::DArray)" begin
67+ DC = copy (D)
6868 @test D == DC
69+ close (DC)
6970 end
7071
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)
7274 @spawnat OTHERIDS localpart (DC)[1 ] = 0
7375 @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)
74105 end
75106
76107 close (D)
77- close (DC)
78108end
79109
80110check_leaks ()
You can’t perform that action at this time.
0 commit comments