Skip to content

Commit 7d21389

Browse files
authored
Merge pull request #152 from JuliaParallel/fbot/deps
Fix deprecations
2 parents 3996ddd + aaf43e6 commit 7d21389

File tree

6 files changed

+47
-77
lines changed

6 files changed

+47
-77
lines changed

src/darray.jl

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ For example, the `dfill` function that creates a distributed array and fills it
2222
dfill(v, args...) = DArray(I->fill(v, map(length,I)), args...)
2323
```
2424
"""
25-
type DArray{T,N,A} <: AbstractArray{T,N}
25+
mutable struct DArray{T,N,A} <: AbstractArray{T,N}
2626
id::Tuple
2727
dims::NTuple{N,Int}
2828
pids::Array{Int,N} # pids[i]==p ⇒ processor p has piece i
@@ -63,14 +63,14 @@ function d_from_weakref_or_d(id)
6363
return d
6464
end
6565

66-
eltype{T}(::Type{DArray{T}}) = T
66+
eltype(::Type{DArray{T}}) where {T} = T
6767
empty_localpart(T,N,A) = A(Array{T}(ntuple(zero, N)))
6868

6969
const SubDArray{T,N,D<:DArray} = SubArray{T,N,D}
7070
const SubOrDArray{T,N} = Union{DArray{T,N}, SubDArray{T,N}}
7171

72-
localtype{T,N,S}(::Type{DArray{T,N,S}}) = S
73-
localtype{T,N,D}(::Type{SubDArray{T,N,D}}) = localtype(D)
72+
localtype(::Type{DArray{T,N,S}}) where {T,N,S} = S
73+
localtype(::Type{SubDArray{T,N,D}}) where {T,N,D} = localtype(D)
7474
localtype(A::SubOrDArray) = localtype(typeof(A))
7575
localtype(A::AbstractArray) = typeof(A)
7676

@@ -153,7 +153,7 @@ function ddata(;T::Type=Any, init::Function=I->nothing, pids=workers(), data::Ve
153153
d
154154
end
155155

156-
function gather{T}(d::DArray{T,1,T})
156+
function gather(d::DArray{T,1,T}) where T
157157
a=Array{T}(length(procs(d)))
158158
@sync for (i,p) in enumerate(procs(d))
159159
@async a[i] = remotecall_fetch(localpart, p, d)
@@ -245,12 +245,12 @@ sz_localpart_ref(ref, id) = size(fetch(ref))
245245

246246
Base.similar(d::DArray, T::Type, dims::Dims) = DArray(I->Array{T}(map(length,I)), dims, procs(d))
247247
Base.similar(d::DArray, T::Type) = similar(d, T, size(d))
248-
Base.similar{T}(d::DArray{T}, dims::Dims) = similar(d, T, dims)
249-
Base.similar{T}(d::DArray{T}) = similar(d, T, size(d))
248+
Base.similar(d::DArray{T}, dims::Dims) where {T} = similar(d, T, dims)
249+
Base.similar(d::DArray{T}) where {T} = similar(d, T, size(d))
250250

251251
Base.size(d::DArray) = d.dims
252252

253-
chunktype{T,N,A}(d::DArray{T,N,A}) = A
253+
chunktype(d::DArray{T,N,A}) where {T,N,A} = A
254254

255255
## chunk index utilities ##
256256

@@ -324,7 +324,7 @@ d[:L], d[:l], d[:LP], d[:lp] are an alternative means to get localparts.
324324
This syntaxt can also be used for assignment. For example,
325325
`d[:L]=v` will assign `v` to the localpart of `d`.
326326
"""
327-
function localpart{T,N,A}(d::DArray{T,N,A})
327+
function localpart(d::DArray{T,N,A}) where {T,N,A}
328328
lpidx = localpartindex(d)
329329
if lpidx == 0
330330
return empty_localpart(T,N,A)::A
@@ -341,15 +341,15 @@ function Base.getindex(d::DArray, s::Symbol)
341341
return localpart(d)
342342
end
343343

344-
function Base.setindex!{T,N,A}(d::DArray{T,N,A}, new_lp::A, s::Symbol)
344+
function Base.setindex!(d::DArray{T,N,A}, new_lp::A, s::Symbol) where {T,N,A}
345345
@assert s in [:L, :l, :LP, :lp]
346346
d.localpart = new_lp
347347
new_lp
348348
end
349349

350350

351351
# fetch localpart of d at pids[i]
352-
fetch{T,N,A}(d::DArray{T,N,A}, i) = remotecall_fetch(localpart, d.pids[i], d)
352+
fetch(d::DArray{T,N,A}, i) where {T,N,A} = remotecall_fetch(localpart, d.pids[i], d)
353353

354354
"""
355355
localindexes(d)
@@ -369,7 +369,7 @@ end
369369
locate(d::DArray, I::Int...) =
370370
ntuple(i -> searchsortedlast(d.cuts[i], I[i]), ndims(d))
371371

372-
chunk{T,N,A}(d::DArray{T,N,A}, i...) = remotecall_fetch(localpart, d.pids[i...], d)::A
372+
chunk(d::DArray{T,N,A}, i...) where {T,N,A} = remotecall_fetch(localpart, d.pids[i...], d)::A
373373

374374
## convenience constructors ##
375375

@@ -380,8 +380,8 @@ Construct a distributed array of zeros.
380380
Trailing arguments are the same as those accepted by `DArray`.
381381
"""
382382
dzeros(dims::Dims, args...) = DArray(I->zeros(map(length,I)), dims, args...)
383-
dzeros{T}(::Type{T}, dims::Dims, args...) = DArray(I->zeros(T,map(length,I)), dims, args...)
384-
dzeros{T}(::Type{T}, d1::Integer, drest::Integer...) = dzeros(T, convert(Dims, tuple(d1, drest...)))
383+
dzeros(::Type{T}, dims::Dims, args...) where {T} = DArray(I->zeros(T,map(length,I)), dims, args...)
384+
dzeros(::Type{T}, d1::Integer, drest::Integer...) where {T} = dzeros(T, convert(Dims, tuple(d1, drest...)))
385385
dzeros(d1::Integer, drest::Integer...) = dzeros(Float64, convert(Dims, tuple(d1, drest...)))
386386
dzeros(d::Dims) = dzeros(Float64, d)
387387

@@ -393,8 +393,8 @@ Construct a distributed array of ones.
393393
Trailing arguments are the same as those accepted by `DArray`.
394394
"""
395395
dones(dims::Dims, args...) = DArray(I->ones(map(length,I)), dims, args...)
396-
dones{T}(::Type{T}, dims::Dims, args...) = DArray(I->ones(T,map(length,I)), dims, args...)
397-
dones{T}(::Type{T}, d1::Integer, drest::Integer...) = dones(T, convert(Dims, tuple(d1, drest...)))
396+
dones(::Type{T}, dims::Dims, args...) where {T} = DArray(I->ones(T,map(length,I)), dims, args...)
397+
dones(::Type{T}, d1::Integer, drest::Integer...) where {T} = dones(T, convert(Dims, tuple(d1, drest...)))
398398
dones(d1::Integer, drest::Integer...) = dones(Float64, convert(Dims, tuple(d1, drest...)))
399399
dones(d::Dims) = dones(Float64, d)
400400

@@ -465,9 +465,9 @@ function distribute(A::AbstractArray, DA::DArray)
465465
return DArray(I->localpart(s), DA)
466466
end
467467

468-
Base.convert{T,N,S<:AbstractArray}(::Type{DArray{T,N,S}}, A::S) = distribute(convert(AbstractArray{T,N}, A))
468+
Base.convert(::Type{DArray{T,N,S}}, A::S) where {T,N,S<:AbstractArray} = distribute(convert(AbstractArray{T,N}, A))
469469

470-
Base.convert{S,T,N}(::Type{Array{S,N}}, d::DArray{T,N}) = begin
470+
Base.convert(::Type{Array{S,N}}, d::DArray{T,N}) where {S,T,N} = begin
471471
a = Array{S}(size(d))
472472
@sync begin
473473
for i = 1:length(d.pids)
@@ -477,7 +477,7 @@ Base.convert{S,T,N}(::Type{Array{S,N}}, d::DArray{T,N}) = begin
477477
return a
478478
end
479479

480-
Base.convert{S,T,N}(::Type{Array{S,N}}, s::SubDArray{T,N}) = begin
480+
Base.convert(::Type{Array{S,N}}, s::SubDArray{T,N}) where {S,T,N} = begin
481481
I = s.indexes
482482
d = s.parent
483483
if isa(I,Tuple{Vararg{UnitRange{Int}}}) && S<:T && T<:S
@@ -492,7 +492,7 @@ Base.convert{S,T,N}(::Type{Array{S,N}}, s::SubDArray{T,N}) = begin
492492
return a
493493
end
494494

495-
function Base.convert{T,N}(::Type{DArray}, SD::SubArray{T,N})
495+
function Base.convert(::Type{DArray}, SD::SubArray{T,N}) where {T,N}
496496
D = SD.parent
497497
DArray(size(SD), procs(D)) do I
498498
TR = typeof(SD.indexes[1])
@@ -511,7 +511,7 @@ function Base.convert{T,N}(::Type{DArray}, SD::SubArray{T,N})
511511
end
512512
end
513513

514-
Base.reshape{T,S<:Array}(A::DArray{T,1,S}, d::Dims) = begin
514+
Base.reshape(A::DArray{T,1,S}, d::Dims) where {T,S<:Array} = begin
515515
if prod(d) != length(A)
516516
throw(DimensionMismatch("dimensions must be consistent with array size"))
517517
end
@@ -539,7 +539,7 @@ end
539539
## indexing ##
540540

541541
getlocalindex(d::DArray, idx...) = localpart(d)[idx...]
542-
function getindex_tuple{T}(d::DArray{T}, I::Tuple{Vararg{Int}})
542+
function getindex_tuple(d::DArray{T}, I::Tuple{Vararg{Int}}) where T
543543
chidx = locate(d, I...)
544544
idxs = d.indexes[chidx...]
545545
localidx = ntuple(i -> (I[i] - first(idxs[i]) + 1), ndims(d))
@@ -626,22 +626,22 @@ function restrict_indices(a::Tuple{Any, Any, Vararg{Any}}, b::Tuple{Any})
626626
end
627627
end
628628

629-
immutable ProductIndices{I,N} <: AbstractArray{Bool, N}
629+
struct ProductIndices{I,N} <: AbstractArray{Bool, N}
630630
indices::I
631631
sz::NTuple{N,Int}
632632
end
633633
Base.size(P::ProductIndices) = P.sz
634634
# This gets passed to map to avoid breaking propagation of inbounds
635635
Base.@propagate_inbounds propagate_getindex(A, I...) = A[I...]
636-
Base.@propagate_inbounds Base.getindex{_,N}(P::ProductIndices{_,N}, I::Vararg{Int, N}) =
636+
Base.@propagate_inbounds Base.getindex(P::ProductIndices{_,N}, I::Vararg{Int, N}) where {_,N} =
637637
Bool((&)(map(propagate_getindex, P.indices, I)...))
638638

639-
immutable MergedIndices{I,N} <: AbstractArray{CartesianIndex{N}, N}
639+
struct MergedIndices{I,N} <: AbstractArray{CartesianIndex{N}, N}
640640
indices::I
641641
sz::NTuple{N,Int}
642642
end
643643
Base.size(M::MergedIndices) = M.sz
644-
Base.@propagate_inbounds Base.getindex{_,N}(M::MergedIndices{_,N}, I::Vararg{Int, N}) =
644+
Base.@propagate_inbounds Base.getindex(M::MergedIndices{_,N}, I::Vararg{Int, N}) where {_,N} =
645645
CartesianIndex(map(propagate_getindex, M.indices, I))
646646
# Additionally, we optimize bounds checking when using MergedIndices as an
647647
# array index since checking, e.g., A[1:500, 1:500] is *way* faster than

src/linalg.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
function Base.ctranspose{T}(D::DArray{T,2})
1+
function Base.ctranspose(D::DArray{T,2}) where T
22
DArray(reverse(size(D)), procs(D)) do I
33
lp = Array{T}(map(length, I))
44
rp = convert(Array, D[reverse(I)...])
55
ctranspose!(lp, rp)
66
end
77
end
88

9-
function Base.transpose{T}(D::DArray{T,2})
9+
function Base.transpose(D::DArray{T,2}) where T
1010
DArray(reverse(size(D)), procs(D)) do I
1111
lp = Array{T}(map(length, I))
1212
rp = convert(Array, D[reverse(I)...])

src/mapreduce.jl

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
Base.map(f, d::DArray) = DArray(I->map(f, localpart(d)), d)
44

5-
Base.map!{F}(f::F, dest::DArray, src::DArray) = begin
5+
Base.map!(f::F, dest::DArray, src::DArray) where {F} = begin
66
@sync for p in procs(dest)
77
@async remotecall_fetch(() -> (map!(f, localpart(dest), src[localindexes(dest)...]); nothing), p)
88
end
99
return dest
1010
end
1111

12-
Base.Broadcast._containertype{D<:DArray}(::Type{D}) = DArray
12+
Base.Broadcast._containertype(::Type{D}) where {D<:DArray} = DArray
1313

1414
Base.Broadcast.promote_containertype(::Type{DArray}, ::Type{DArray}) = DArray
1515
Base.Broadcast.promote_containertype(::Type{DArray}, ::Type{Array}) = DArray
@@ -61,7 +61,7 @@ Base.mapreduce(f, opt::Function, d::DArray) = _mapreduce(f, opt, d)
6161
Base.mapreduce(f, opt, d::DArray) = _mapreduce(f, opt, d)
6262

6363
# mapreducedim
64-
Base.reducedim_initarray{R}(A::DArray, region, v0, ::Type{R}) = begin
64+
Base.reducedim_initarray(A::DArray, region, v0, ::Type{R}) where {R} = begin
6565
# Store reduction on lowest pids
6666
pids = A.pids[ntuple(i -> i in region ? (1:1) : (:), ndims(A))...]
6767
chunks = similar(pids, Future)
@@ -70,9 +70,9 @@ Base.reducedim_initarray{R}(A::DArray, region, v0, ::Type{R}) = begin
7070
end
7171
return DArray(chunks)
7272
end
73-
Base.reducedim_initarray{T}(A::DArray, region, v0::T) = Base.reducedim_initarray(A, region, v0, T)
73+
Base.reducedim_initarray(A::DArray, region, v0::T) where {T} = Base.reducedim_initarray(A, region, v0, T)
7474

75-
Base.reducedim_initarray0{R}(A::DArray, region, v0, ::Type{R}) = begin
75+
Base.reducedim_initarray0(A::DArray, region, v0, ::Type{R}) where {R} = begin
7676
# Store reduction on lowest pids
7777
pids = A.pids[ntuple(i -> i in region ? (1:1) : (:), ndims(A))...]
7878
chunks = similar(pids, Future)
@@ -81,7 +81,7 @@ Base.reducedim_initarray0{R}(A::DArray, region, v0, ::Type{R}) = begin
8181
end
8282
return DArray(chunks)
8383
end
84-
Base.reducedim_initarray0{T}(A::DArray, region, v0::T) = Base.reducedim_initarray0(A, region, v0, T)
84+
Base.reducedim_initarray0(A::DArray, region, v0::T) where {T} = Base.reducedim_initarray0(A, region, v0, T)
8585

8686
# Compute mapreducedim of each localpart and store the result in a new DArray
8787
mapreducedim_within(f, op, A::DArray, region) = begin
@@ -180,17 +180,6 @@ end
180180
# Unary vector functions
181181
(-)(D::DArray) = map(-, D)
182182

183-
@static if VERSION < v"0.6.0-dev.1731"
184-
# scalar ops
185-
(+)(A::DArray{Bool}, x::Bool) = A .+ x
186-
(+)(x::Bool, A::DArray{Bool}) = x .+ A
187-
(-)(A::DArray{Bool}, x::Bool) = A .- x
188-
(-)(x::Bool, A::DArray{Bool}) = x .- A
189-
(+)(A::DArray, x::Number) = A .+ x
190-
(+)(x::Number, A::DArray) = x .+ A
191-
(-)(A::DArray, x::Number) = A .- x
192-
(-)(x::Number, A::DArray) = x .- A
193-
end
194183

195184
map_localparts(f::Callable, d::DArray) = DArray(i->f(localpart(d)), d)
196185
map_localparts(f::Callable, d1::DArray, d2::DArray) = DArray(d1) do I
@@ -226,14 +215,6 @@ end
226215
# the same size and distribution
227216
map_localparts(f::Callable, As::DArray...) = DArray(I->f(map(localpart, As)...), As[1])
228217

229-
@static if VERSION < v"0.6.0-dev.1632"
230-
for f in (:.+, :.-, :.*, :./, :.%, :.<<, :.>>, :div, :mod, :rem, :&, :|, :$)
231-
@eval begin
232-
($f){T}(A::DArray{T}, B::Number) = map_localparts(r->($f)(r, B), A)
233-
($f){T}(A::Number, B::DArray{T}) = map_localparts(r->($f)(A, r), B)
234-
end
235-
end
236-
end
237218

238219
function samedist(A::DArray, B::DArray)
239220
(size(A) == size(B)) || throw(DimensionMismatch())
@@ -245,27 +226,16 @@ end
245226

246227
for f in (:+, :-, :div, :mod, :rem, :&, :|, :$)
247228
@eval begin
248-
function ($f){T}(A::DArray{T}, B::DArray{T})
229+
function ($f)(A::DArray{T}, B::DArray{T}) where T
249230
B = samedist(A, B)
250231
map_localparts($f, A, B)
251232
end
252-
($f){T}(A::DArray{T}, B::Array{T}) = map_localparts($f, A, B)
253-
($f){T}(A::Array{T}, B::DArray{T}) = map_localparts($f, A, B)
254-
end
255-
end
256-
@static if VERSION < v"0.6.0-dev.1632"
257-
for f in (:.+, :.-, :.*, :./, :.%, :.<<, :.>>)
258-
@eval begin
259-
function ($f){T}(A::DArray{T}, B::DArray{T})
260-
map_localparts($f, A, B)
261-
end
262-
($f){T}(A::DArray{T}, B::Array{T}) = map_localparts($f, A, B)
263-
($f){T}(A::Array{T}, B::DArray{T}) = map_localparts($f, A, B)
264-
end
233+
($f)(A::DArray{T}, B::Array{T}) where {T} = map_localparts($f, A, B)
234+
($f)(A::Array{T}, B::DArray{T}) where {T} = map_localparts($f, A, B)
265235
end
266236
end
267237

268-
function mapslices{T,N,A}(f::Function, D::DArray{T,N,A}, dims::AbstractVector)
238+
function mapslices(f::Function, D::DArray{T,N,A}, dims::AbstractVector) where {T,N,A}
269239
if !all(t -> t == 1, size(D.indexes)[dims])
270240
p = ones(Int, ndims(D))
271241
nondims = filter(t -> !(t in dims), 1:ndims(D))

src/serialize.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function Base.serialize{T,N,A}(S::AbstractSerializer, d::DArray{T,N,A})
1+
function Base.serialize(S::AbstractSerializer, d::DArray{T,N,A}) where {T,N,A}
22
# Only send the ident for participating workers - we expect the DArray to exist in the
33
# remote registry. DO NOT send the localpart.
44
destpid = Base.worker_id_from_socket(S.io)
@@ -14,7 +14,7 @@ function Base.serialize{T,N,A}(S::AbstractSerializer, d::DArray{T,N,A})
1414
end
1515
end
1616

17-
function Base.deserialize{DT<:DArray}(S::AbstractSerializer, t::Type{DT})
17+
function Base.deserialize(S::AbstractSerializer, t::Type{DT}) where DT<:DArray
1818
what = deserialize(S)
1919
id_only = what[1]
2020
id = what[2]
@@ -42,7 +42,7 @@ function Base.deserialize{DT<:DArray}(S::AbstractSerializer, t::Type{DT})
4242
end
4343

4444
# Serialize only those parts of the object as required by the destination worker.
45-
type DestinationSerializer
45+
mutable struct DestinationSerializer
4646
generate::Nullable{Function} # Function to generate the part to be serialized
4747
pids::Nullable{Array} # MUST have the same shape as the distribution
4848

@@ -68,7 +68,7 @@ function Base.serialize(S::AbstractSerializer, s::DestinationSerializer)
6868
serialize(S, get(s.generate)(pididx))
6969
end
7070

71-
function Base.deserialize{T<:DestinationSerializer}(S::AbstractSerializer, t::Type{T})
71+
function Base.deserialize(S::AbstractSerializer, t::Type{T}) where T<:DestinationSerializer
7272
lpart = deserialize(S)
7373
return DestinationSerializer(lpart)
7474
end

src/sort.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function sample_n_setup_ref(d::DVector, sample_size; kwargs...)
1414
end
1515

1616

17-
function scatter_n_sort_localparts{T}(d, myidx, refs, boundaries::Array{T}; by = identity, kwargs...)
17+
function scatter_n_sort_localparts(d, myidx, refs, boundaries::Array{T}; by = identity, kwargs...) where T
1818
if d==nothing
1919
sorted = take!(refs[myidx]) # First entry in the remote channel is sorted localpart
2020
else
@@ -59,7 +59,7 @@ function scatter_n_sort_localparts{T}(d, myidx, refs, boundaries::Array{T}; by =
5959
return (sorted_ref, length(lp_sorting))
6060
end
6161

62-
function compute_boundaries{T}(d::DVector{T}; kwargs...)
62+
function compute_boundaries(d::DVector{T}; kwargs...) where T
6363
pids = procs(d)
6464
np = length(pids)
6565
sample_sz_on_wrkr = 512
@@ -100,7 +100,7 @@ Keyword argument `sample` can take values:
100100
101101
Keyword argument `alg` takes the same options `Base.sort`
102102
"""
103-
function Base.sort{T}(d::DVector{T}; sample=true, kwargs...)
103+
function Base.sort(d::DVector{T}; sample=true, kwargs...) where T
104104
pids = procs(d)
105105
np = length(pids)
106106

src/spmd.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ export sendto, recvfrom, recvfrom_any, barrier, bcast, scatter, gather
55
export context_local_storage, context, spmd, close
66

77

8-
type WorkerDataChannel
8+
mutable struct WorkerDataChannel
99
pid::Int
1010
rc::Nullable{RemoteChannel}
1111
lock::ReentrantLock
1212

1313
WorkerDataChannel(pid) = new(pid, Nullable{RemoteChannel}(), ReentrantLock())
1414
end
1515

16-
type SPMDContext
16+
mutable struct SPMDContext
1717
id::Tuple
1818
chnl::Channel
1919
store::Dict{Any,Any}

0 commit comments

Comments
 (0)