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