Skip to content

Commit a77e35b

Browse files
traktofonandreasnoack
authored andcommitted
Fix more deprecations.
1 parent ce8bb40 commit a77e35b

File tree

4 files changed

+50
-45
lines changed

4 files changed

+50
-45
lines changed

src/linalg.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function axpy!(α, x::DArray, y::DArray)
2525
end
2626
asyncmap(procs(y)) do p
2727
@async remotecall_fetch(p) do
28-
Base.axpy!(α, localpart(x), localpart(y))
28+
axpy!(α, localpart(x), localpart(y))
2929
return nothing
3030
end
3131
end
@@ -192,7 +192,7 @@ end
192192
function _matmatmul!::Number, A::DMatrix, B::AbstractMatrix, β::Number, C::DMatrix, tA)
193193
# error checks
194194
Ad1, Ad2 = (tA == 'N') ? (1,2) : (2,1)
195-
mA, nA = size(A, Ad1, Ad2)
195+
mA, nA = (size(A, Ad1), size(A, Ad2))
196196
mB, nB = size(B)
197197
if mB != nA
198198
throw(DimensionMismatch("matrix A has dimensions ($mA, $nA), matrix B has dimensions ($mB, $nB)"))
@@ -263,12 +263,12 @@ _matmul_op = (t,s) -> t*s + t*s
263263

264264
function Base.:*(A::DMatrix, x::AbstractVector)
265265
T = Base.promote_op(_matmul_op, eltype(A), eltype(x))
266-
y = DArray(I -> Array{T}(map(length, I)), (size(A, 1),), procs(A)[:,1], (size(procs(A), 1),))
266+
y = DArray(I -> Array{T}(undef, map(length, I)), (size(A, 1),), procs(A)[:,1], (size(procs(A), 1),))
267267
return A_mul_B!(one(T), A, x, zero(T), y)
268268
end
269269
function Base.:*(A::DMatrix, B::AbstractMatrix)
270270
T = Base.promote_op(_matmul_op, eltype(A), eltype(B))
271-
C = DArray(I -> Array{T}(map(length, I)),
271+
C = DArray(I -> Array{T}(undef, map(length, I)),
272272
(size(A, 1), size(B, 2)),
273273
procs(A)[:,1:min(size(procs(A), 2), size(procs(B), 2))],
274274
(size(procs(A), 1), min(size(procs(A), 2), size(procs(B), 2))))
@@ -277,15 +277,15 @@ end
277277

278278
function Ac_mul_B(A::DMatrix, x::AbstractVector)
279279
T = Base.promote_op(_matmul_op, eltype(A), eltype(x))
280-
y = DArray(I -> Array{T}(map(length, I)),
280+
y = DArray(I -> Array{T}(undef, map(length, I)),
281281
(size(A, 2),),
282282
procs(A)[1,:],
283283
(size(procs(A), 2),))
284284
return Ac_mul_B!(one(T), A, x, zero(T), y)
285285
end
286286
function Ac_mul_B(A::DMatrix, B::AbstractMatrix)
287287
T = Base.promote_op(_matmul_op, eltype(A), eltype(B))
288-
C = DArray(I -> Array{T}(map(length, I)), (size(A, 2),
288+
C = DArray(I -> Array{T}(undef, map(length, I)), (size(A, 2),
289289
size(B, 2)),
290290
procs(A)[1:min(size(procs(A), 1), size(procs(B), 2)),:],
291291
(size(procs(A), 2), min(size(procs(A), 1), size(procs(B), 2))))

src/mapreduce.jl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## higher-order functions ##
22

33
import Base: +, -, div, mod, rem, &, |, xor
4+
import SparseArrays: nnz
45

56
Base.map(f, d0::DArray, ds::AbstractArray...) = broadcast(f, d0, ds...)
67

@@ -21,7 +22,7 @@ Base.BroadcastStyle(::Type{<:DArray}, ::Any) = Broadcast.ArrayStyle{DArray}()
2122

2223
function Base.similar(bc::Broadcast.Broadcasted{Broadcast.ArrayStyle{DArray}}, ::Type{ElType}) where {ElType}
2324
DA = find_darray(bc)
24-
similar(DA, ElType)
25+
DArray(I -> Array{ElType}(undef, map(length,I)), DA)
2526
end
2627

2728
"`DA = find_darray(As)` returns the first DArray among the arguments."
@@ -201,18 +202,21 @@ for f in (:+, :-, :div, :mod, :rem, :&, :|, :xor)
201202
end
202203
end
203204

204-
function mapslices(f::Function, D::DArray{T,N,A}, dims::AbstractVector) where {T,N,A}
205+
function Base.mapslices(f, D::DArray{T,N,A}; dims) where {T,N,A}
206+
if !(dims isa AbstractVector)
207+
dims = [dims...]
208+
end
205209
if !all(t -> t == 1, size(D.indices)[dims])
206210
p = ones(Int, ndims(D))
207211
nondims = filter(t -> !(t in dims), 1:ndims(D))
208212
p[nondims] = defaultdist([size(D)...][[nondims...]], procs(D))
209213
DD = DArray(size(D), procs(D), p) do I
210214
return convert(A, D[I...])
211215
end
212-
return mapslices(f, DD, dims)
216+
return mapslices(f, DD, dims=dims)
213217
end
214218

215-
refs = Future[remotecall((x,y,z)->mapslices(x,localpart(y),z), p, f, D, dims) for p in procs(D)]
219+
refs = Future[remotecall((x,y,z)->mapslices(x,localpart(y),dims=z), p, f, D, dims) for p in procs(D)]
216220

217221
DArray(reshape(refs, size(procs(D))))
218222
end
@@ -246,7 +250,7 @@ function _ppeval(f, A...; dim = map(ndims, A))
246250
push!(ridx, 1)
247251
Rsize = map(last, ridx)
248252
Rsize[end] = dimlength
249-
R = Array{eltype(R1)}(Rsize...)
253+
R = Array{eltype(R1)}(undef, Rsize...)
250254

251255
for i = 1:dimlength
252256
for j = 1:narg
@@ -273,7 +277,7 @@ Evaluates the callable argument `f` on slices of the elements of the `D` tuple.
273277
`f` can be any callable object that accepts sliced or broadcasted elements of `D`.
274278
The result returned from `f` must be either an array or a scalar.
275279
276-
`D` has any number of elements and the alements can have any type. If an element
280+
`D` has any number of elements and the elements can have any type. If an element
277281
of `D` is a distributed array along the dimension specified by `dim`. If an
278282
element of `D` is not distributed, the element is by default broadcasted and
279283
applied on all evaluations of `f`.
@@ -286,7 +290,7 @@ broadcasted to all evaluations of `f`.
286290
287291
#### Result
288292
`ppeval` returns a distributed array of dimension `p+1` where the first `p`
289-
sizes correspond to the sizes of return values of `f`. The last dimention of
293+
sizes correspond to the sizes of return values of `f`. The last dimension of
290294
the return array from `ppeval` has the same length as the dimension over which
291295
the input arrays are sliced.
292296

src/sort.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function scatter_n_sort_localparts(d, myidx, refs, boundaries::Array{T}; by = id
3838
end
3939

4040
if p_till == p_sorted
41-
@async put!(r, Array{T}(0))
41+
@async put!(r, Array{T}(undef,0))
4242
else
4343
v = sorted[p_sorted:p_till-1]
4444
@async put!(r, v)
@@ -66,7 +66,7 @@ function compute_boundaries(d::DVector{T}; kwargs...) where T
6666

6767
results = asyncmap(p -> remotecall_fetch(sample_n_setup_ref, p, d, sample_sz_on_wrkr; kwargs...), pids)
6868

69-
samples = Array{T}(undef, 0)
69+
samples = Array{T}(undef,0)
7070
for x in results
7171
append!(samples, x[1])
7272
end
@@ -128,7 +128,7 @@ function Base.sort(d::DVector{T}; sample=true, kwargs...) where T
128128

129129
@assert lb<=ub
130130

131-
s = Array{T}(np)
131+
s = Array{T}(undef,np)
132132
part = abs(ub - lb)/np
133133
(isnan(part) || isinf(part)) && throw(ArgumentError("lower and upper bounds must not be infinities"))
134134

@@ -155,7 +155,7 @@ function Base.sort(d::DVector{T}; sample=true, kwargs...) where T
155155
throw(ArgumentError("keyword arg `sample` must be Boolean, Tuple(Min,Max) or an actual sample of data : " * string(sample)))
156156
end
157157

158-
local_sort_results = Array{Tuple}(np)
158+
local_sort_results = Array{Tuple}(undef,np)
159159

160160
Base.asyncmap!((i,p) -> remotecall_fetch(
161161
scatter_n_sort_localparts, p, presorted ? nothing : d, i, refs, boundaries; kwargs...),

test/darray.jl

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Test, LinearAlgebra, SpecialFunctions
22
using Statistics: mean
3+
using SparseArrays: nnz
34
@everywhere using SparseArrays: sprandn
45

56
@testset "test distribute and other constructors" begin
@@ -713,35 +714,35 @@ check_leaks()
713714
@testset "test mapslices" begin
714715
A = randn(5,5,5)
715716
D = distribute(A, procs = workers(), dist = [1, 1, min(nworkers(), 5)])
716-
@test mapslices(svdvals, D, (1,2)) mapslices(svdvals, A, (1,2))
717-
@test mapslices(svdvals, D, (1,3)) mapslices(svdvals, A, (1,3))
718-
@test mapslices(svdvals, D, (2,3)) mapslices(svdvals, A, (2,3))
719-
@test mapslices(sort, D, (1,)) mapslices(sort, A, (1,))
720-
@test mapslices(sort, D, (2,)) mapslices(sort, A, (2,))
721-
@test mapslices(sort, D, (3,)) mapslices(sort, A, (3,))
717+
@test mapslices(svdvals, D, dims=(1,2)) mapslices(svdvals, A, dims=(1,2))
718+
@test mapslices(svdvals, D, dims=(1,3)) mapslices(svdvals, A, dims=(1,3))
719+
@test mapslices(svdvals, D, dims=(2,3)) mapslices(svdvals, A, dims=(2,3))
720+
@test mapslices(sort, D, dims=(1,)) mapslices(sort, A, dims=(1,))
721+
@test mapslices(sort, D, dims=(2,)) mapslices(sort, A, dims=(2,))
722+
@test mapslices(sort, D, dims=(3,)) mapslices(sort, A, dims=(3,))
722723

723724
# issue #3613
724-
B = mapslices(sum, dones(Float64, (2,3,4), workers(), [1,1,min(nworkers(),4)]), [1,2])
725+
B = mapslices(sum, dones(Float64, (2,3,4), workers(), [1,1,min(nworkers(),4)]), dims=[1,2])
725726
@test size(B) == (1,1,4)
726727
@test all(B.==6)
727728

728729
# issue #5141
729-
C1 = mapslices(x-> maximum(-x), D, [])
730+
C1 = mapslices(x-> maximum(-x), D, dims=[])
730731
@test C1 == -D
731732

732733
# issue #5177
733734
c = dones(Float64, (2,3,4,5), workers(), [1,1,1,min(nworkers(),5)])
734-
m1 = mapslices(x-> ones(2,3), c, [1,2])
735-
m2 = mapslices(x-> ones(2,4), c, [1,3])
736-
m3 = mapslices(x-> ones(3,4), c, [2,3])
735+
m1 = mapslices(x-> ones(2,3), c, dims=[1,2])
736+
m2 = mapslices(x-> ones(2,4), c, dims=[1,3])
737+
m3 = mapslices(x-> ones(3,4), c, dims=[2,3])
737738
@test size(m1) == size(m2) == size(m3) == size(c)
738739

739-
n1 = mapslices(x-> ones(6), c, [1,2])
740-
n2 = mapslices(x-> ones(6), c, [1,3])
741-
n3 = mapslices(x-> ones(6), c, [2,3])
742-
n1a = mapslices(x-> ones(1,6), c, [1,2])
743-
n2a = mapslices(x-> ones(1,6), c, [1,3])
744-
n3a = mapslices(x-> ones(1,6), c, [2,3])
740+
n1 = mapslices(x-> ones(6), c, dims=[1,2])
741+
n2 = mapslices(x-> ones(6), c, dims=[1,3])
742+
n3 = mapslices(x-> ones(6), c, dims=[2,3])
743+
n1a = mapslices(x-> ones(1,6), c, dims=[1,2])
744+
n2a = mapslices(x-> ones(1,6), c, dims=[1,3])
745+
n3a = mapslices(x-> ones(1,6), c, dims=[2,3])
745746
@test (size(n1a) == (1,6,4,5) && size(n2a) == (1,3,6,5) && size(n3a) == (2,1,6,5))
746747
@test (size(n1) == (6,1,4,5) && size(n2) == (6,3,1,5) && size(n3) == (2,6,1,5))
747748
close(D)
@@ -757,22 +758,22 @@ check_leaks()
757758
c = drand(20,20)
758759
d = convert(Array, c)
759760

760-
@testset "$f" for f in (:+, :-, :.+, :.-, :.*, :./, :.%)
761+
@testset "$f" for f in (:+, :-, :*, :/, :%)
761762
x = rand()
762-
@test @eval ($f)($a, $x) == ($f)($b, $x)
763-
@test @eval ($f)($x, $a) == ($f)($x, $b)
764-
@test @eval ($f)($a, $c) == ($f)($b, $d)
763+
@test @eval ($f).($a, $x) == ($f).($b, $x)
764+
@test @eval ($f).($x, $a) == ($f).($x, $b)
765+
@test @eval ($f).($a, $c) == ($f).($b, $d)
765766
end
766767

767768
close(a)
768769
close(c)
769770

770771
a = dones(Int, 20, 20)
771772
b = convert(Array, a)
772-
@testset "$f" for f in (:.<<, :.>>)
773-
@test @eval ($f)($a, 2) == ($f)($b, 2)
774-
@test @eval ($f)(2, $a) == ($f)(2, $b)
775-
@test @eval ($f)($a, $a) == ($f)($b, $b)
773+
@testset "$f" for f in (:<<, :>>)
774+
@test @eval ($f).($a, 2) == ($f).($b, 2)
775+
@test @eval ($f).(2, $a) == ($f).(2, $b)
776+
@test @eval ($f).($a, $a) == ($f).($b, $b)
776777
end
777778

778779
@testset "$f" for f in (:rem,)
@@ -792,7 +793,7 @@ check_leaks()
792793
nrows = 20 * nwrkrs
793794
ncols = 10 * nwrkrs
794795
a = drand((nrows,ncols), wrkrs, (1, nwrkrs))
795-
m = mean(a, 1)
796+
m = mean(a, dims=1)
796797
c = a .- m
797798
d = convert(Array, a) .- convert(Array, m)
798799
@test c == d
@@ -854,7 +855,7 @@ check_leaks()
854855
R[:, i] = convert(Array, A)[:, :, i]*convert(Array, B)[:, i]
855856
end
856857
@test convert(Array, ppeval(*, A, B)) R
857-
@test sum(ppeval(eigvals, A)) sum(ppeval(eigvals, A, eye(10, 10)))
858+
@test sum(ppeval(eigvals, A)) sum(ppeval(eigvals, A, Matrix{Float64}(I,10,10)))
858859
close(A)
859860
close(B)
860861
d_closeall() # close the temporaries created above
@@ -887,7 +888,7 @@ end
887888
d_closeall() # close the temporaries created above
888889
end
889890

890-
@testset "sort, T = $T" for i in 0:6, T in [Int, Float64]
891+
@testset "sort, T = $T, 10^$i elements" for i in 0:6, T in [Int, Float64]
891892
d = DistributedArrays.drand(T, 10^i)
892893
@testset "sample = $sample" for sample in Any[true, false, (minimum(d),maximum(d)), rand(T, 10^i>512 ? 512 : 10^i)]
893894
d2 = DistributedArrays.sort(d; sample=sample)

0 commit comments

Comments
 (0)