@@ -22,7 +22,7 @@ For example, the `dfill` function that creates a distributed array and fills it
2222dfill(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
6464end
6565
66- eltype {T} (:: Type{DArray{T}} ) = T
66+ eltype (:: Type{DArray{T}} ) where {T} = T
6767empty_localpart (T,N,A) = A (Array {T} (ntuple (zero, N)))
6868
6969const SubDArray{T,N,D<: DArray } = SubArray{T,N,D}
7070const 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)
7474localtype (A:: SubOrDArray ) = localtype (typeof (A))
7575localtype (A:: AbstractArray ) = typeof (A)
7676
@@ -153,7 +153,7 @@ function ddata(;T::Type=Any, init::Function=I->nothing, pids=workers(), data::Ve
153153 d
154154end
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
246246Base. similar (d:: DArray , T:: Type , dims:: Dims ) = DArray (I-> Array {T} (map (length,I)), dims, procs (d))
247247Base. 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
251251Base. 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.
324324This 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)
342342end
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
348348end
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)
369369locate (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.
380380Trailing arguments are the same as those accepted by `DArray`.
381381"""
382382dzeros (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... )))
385385dzeros (d1:: Integer , drest:: Integer... ) = dzeros (Float64, convert (Dims, tuple (d1, drest... )))
386386dzeros (d:: Dims ) = dzeros (Float64, d)
387387
@@ -393,8 +393,8 @@ Construct a distributed array of ones.
393393Trailing arguments are the same as those accepted by `DArray`.
394394"""
395395dones (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... )))
398398dones (d1:: Integer , drest:: Integer... ) = dones (Float64, convert (Dims, tuple (d1, drest... )))
399399dones (d:: Dims ) = dones (Float64, d)
400400
@@ -465,9 +465,9 @@ function distribute(A::AbstractArray, DA::DArray)
465465 return DArray (I-> localpart (s), DA)
466466end
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
478478end
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
493493end
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
512512end
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
539539# # indexing ##
540540
541541getlocalindex (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
627627end
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}
632632end
633633Base. size (P:: ProductIndices ) = P. sz
634634# This gets passed to map to avoid breaking propagation of inbounds
635635Base. @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}
642642end
643643Base. 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
0 commit comments