1
1
using LinearAlgebra, SparseArrays, Random, SharedArrays
2
- import Dagger: chunks, DArray , domainchunks, treereduce_nd
2
+ import Dagger: DArray, chunks , domainchunks, treereduce_nd
3
3
import Distributed: myid, procs
4
4
import Statistics: mean, var, std
5
5
import OnlineStats
138
138
139
139
@testset " distributing an array" begin
140
140
function test_dist (X)
141
- X1 = Distribute ( Blocks (10 , 20 ), X )
141
+ X1 = distribute (X, Blocks (10 , 20 ))
142
142
Xc = fetch (X1)
143
143
@test Xc isa DArray{eltype (X),ndims (X)}
144
144
@test Xc == X
147
147
@test map (x-> size (x) == (10 , 20 ), domainchunks (Xc)) |> all
148
148
end
149
149
x = [1 2 ; 3 4 ]
150
- @test Distribute ( Blocks (1 ,1 ), x ) == x
150
+ @test distribute (x, Blocks (1 ,1 )) == x
151
151
test_dist (rand (100 , 100 ))
152
152
test_dist (sprand (100 , 100 , 0.1 ))
153
153
158
158
@testset " transpose" begin
159
159
function test_transpose (X)
160
160
x, y = size (X)
161
- X1 = Distribute ( Blocks (10 , 20 ), X )
161
+ X1 = distribute (X, Blocks (10 , 20 ))
162
162
@test X1' == X'
163
163
Xc = fetch (X1' )
164
164
@test chunks (Xc) |> size == (div (y, 20 ), div (x,10 ))
174
174
@testset " matrix-matrix multiply" begin
175
175
function test_mul (X)
176
176
tol = 1e-12
177
- X1 = Distribute ( Blocks (10 , 20 ), X )
177
+ X1 = distribute (X, Blocks (10 , 20 ))
178
178
@test_throws DimensionMismatch X1* X1
179
179
X2 = X1' * X1
180
180
X3 = X1* X1'
188
188
test_mul (rand (40 , 40 ))
189
189
190
190
x = rand (10 ,10 )
191
- X = Distribute ( Blocks (3 ,3 ), x )
191
+ X = distribute (x, Blocks (3 ,3 ))
192
192
y = rand (10 )
193
193
@test norm (collect (X* y) - x* y) < 1e-13
194
194
end
@@ -202,24 +202,24 @@ end
202
202
203
203
@testset " concat" begin
204
204
m = rand (75 ,75 )
205
- x = Distribute ( Blocks (10 ,20 ), m )
206
- y = Distribute ( Blocks (10 ,10 ), m )
205
+ x = distribute (m, Blocks (10 ,20 ))
206
+ y = distribute (m, Blocks (10 ,10 ))
207
207
@test hcat (m,m) == collect (hcat (x,x)) == collect (hcat (x,y))
208
208
@test vcat (m,m) == collect (vcat (x,x))
209
209
@test_throws DimensionMismatch vcat (x,y)
210
210
end
211
211
212
212
@testset " scale" begin
213
213
x = rand (10 ,10 )
214
- X = Distribute ( Blocks (3 ,3 ), x )
214
+ X = distribute (x, Blocks (3 ,3 ))
215
215
y = rand (10 )
216
216
217
217
@test Diagonal (y)* x == collect (Diagonal (y)* X)
218
218
end
219
219
220
220
@testset " Getindex" begin
221
221
function test_getindex (x)
222
- X = Distribute ( Blocks (3 ,3 ), x )
222
+ X = distribute (x, Blocks (3 ,3 ))
223
223
@test collect (X[3 : 8 , 2 : 7 ]) == x[3 : 8 , 2 : 7 ]
224
224
ragged_idx = [1 ,2 ,9 ,7 ,6 ,2 ,4 ,5 ]
225
225
@test collect (X[ragged_idx, 2 : 7 ]) == x[ragged_idx, 2 : 7 ]
248
248
249
249
250
250
@testset " cleanup" begin
251
- X = Distribute ( Blocks (10 ,10 ), rand (10 ,10 ))
251
+ X = distribute ( rand (10 ,10 ), Blocks (10 ,10 ))
252
252
@test collect (sin .(X)) == collect (sin .(X))
253
253
end
254
254
269
269
x= rand (10 ,10 )
270
270
y= copy (x)
271
271
y[3 : 8 , 2 : 7 ] .= 1.0
272
- X = Distribute ( Blocks (3 ,3 ), x )
272
+ X = distribute (x, Blocks (3 ,3 ))
273
273
@test collect (setindex (X,1.0 , 3 : 8 , 2 : 7 )) == y
274
274
@test collect (X) == x
275
275
end
292
292
@test collect (sort (y)) == x
293
293
294
294
x = ones (10 )
295
- y = Distribute ( Blocks (3 ), x )
295
+ y = distribute (x, Blocks (3 ))
296
296
@test_broken map (x-> length (collect (x)), sort (y). chunks) == [3 ,3 ,3 ,1 ]
297
297
end
298
298
0 commit comments