@@ -22,7 +22,7 @@ For example, the `dfill` function that creates a distributed array and fills it
22
22
dfill(v, args...) = DArray(I->fill(v, map(length,I)), args...)
23
23
```
24
24
"""
25
- type DArray{T,N,A} <: AbstractArray{T,N}
25
+ mutable struct DArray{T,N,A} <: AbstractArray{T,N}
26
26
id:: Tuple
27
27
dims:: NTuple{N,Int}
28
28
pids:: Array{Int,N} # pids[i]==p ⇒ processor p has piece i
@@ -63,14 +63,14 @@ function d_from_weakref_or_d(id)
63
63
return d
64
64
end
65
65
66
- eltype {T} (:: Type{DArray{T}} ) = T
66
+ eltype (:: Type{DArray{T}} ) where {T} = T
67
67
empty_localpart (T,N,A) = A (Array {T} (ntuple (zero, N)))
68
68
69
69
const SubDArray{T,N,D<: DArray } = SubArray{T,N,D}
70
70
const SubOrDArray{T,N} = Union{DArray{T,N}, SubDArray{T,N}}
71
71
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)
74
74
localtype (A:: SubOrDArray ) = localtype (typeof (A))
75
75
localtype (A:: AbstractArray ) = typeof (A)
76
76
@@ -153,7 +153,7 @@ function ddata(;T::Type=Any, init::Function=I->nothing, pids=workers(), data::Ve
153
153
d
154
154
end
155
155
156
- function gather {T} (d:: DArray{T,1,T} )
156
+ function gather (d:: DArray{T,1,T} ) where T
157
157
a= Array {T} (length (procs (d)))
158
158
@sync for (i,p) in enumerate (procs (d))
159
159
@async a[i] = remotecall_fetch (localpart, p, d)
@@ -245,12 +245,12 @@ sz_localpart_ref(ref, id) = size(fetch(ref))
245
245
246
246
Base. similar (d:: DArray , T:: Type , dims:: Dims ) = DArray (I-> Array {T} (map (length,I)), dims, procs (d))
247
247
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))
250
250
251
251
Base. size (d:: DArray ) = d. dims
252
252
253
- chunktype {T,N,A} (d :: DArray {T,N,A}) = A
253
+ chunktype (d :: DArray {T,N,A}) where {T,N,A} = A
254
254
255
255
# # chunk index utilities ##
256
256
@@ -324,7 +324,7 @@ d[:L], d[:l], d[:LP], d[:lp] are an alternative means to get localparts.
324
324
This syntaxt can also be used for assignment. For example,
325
325
`d[:L]=v` will assign `v` to the localpart of `d`.
326
326
"""
327
- function localpart {T,N,A} (d :: DArray {T,N,A})
327
+ function localpart (d :: DArray {T,N,A}) where {T,N,A}
328
328
lpidx = localpartindex (d)
329
329
if lpidx == 0
330
330
return empty_localpart (T,N,A):: A
@@ -341,15 +341,15 @@ function Base.getindex(d::DArray, s::Symbol)
341
341
return localpart (d)
342
342
end
343
343
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}
345
345
@assert s in [:L , :l , :LP , :lp ]
346
346
d. localpart = new_lp
347
347
new_lp
348
348
end
349
349
350
350
351
351
# 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)
353
353
354
354
"""
355
355
localindexes(d)
369
369
locate (d:: DArray , I:: Int... ) =
370
370
ntuple (i -> searchsortedlast (d. cuts[i], I[i]), ndims (d))
371
371
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
373
373
374
374
# # convenience constructors ##
375
375
@@ -380,8 +380,8 @@ Construct a distributed array of zeros.
380
380
Trailing arguments are the same as those accepted by `DArray`.
381
381
"""
382
382
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... )))
385
385
dzeros (d1:: Integer , drest:: Integer... ) = dzeros (Float64, convert (Dims, tuple (d1, drest... )))
386
386
dzeros (d:: Dims ) = dzeros (Float64, d)
387
387
@@ -393,8 +393,8 @@ Construct a distributed array of ones.
393
393
Trailing arguments are the same as those accepted by `DArray`.
394
394
"""
395
395
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... )))
398
398
dones (d1:: Integer , drest:: Integer... ) = dones (Float64, convert (Dims, tuple (d1, drest... )))
399
399
dones (d:: Dims ) = dones (Float64, d)
400
400
@@ -465,9 +465,9 @@ function distribute(A::AbstractArray, DA::DArray)
465
465
return DArray (I-> localpart (s), DA)
466
466
end
467
467
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))
469
469
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
471
471
a = Array {S} (size (d))
472
472
@sync begin
473
473
for i = 1 : length (d. pids)
@@ -477,7 +477,7 @@ Base.convert{S,T,N}(::Type{Array{S,N}}, d::DArray{T,N}) = begin
477
477
return a
478
478
end
479
479
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
481
481
I = s. indexes
482
482
d = s. parent
483
483
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
492
492
return a
493
493
end
494
494
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}
496
496
D = SD. parent
497
497
DArray (size (SD), procs (D)) do I
498
498
TR = typeof (SD. indexes[1 ])
@@ -511,7 +511,7 @@ function Base.convert{T,N}(::Type{DArray}, SD::SubArray{T,N})
511
511
end
512
512
end
513
513
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
515
515
if prod (d) != length (A)
516
516
throw (DimensionMismatch (" dimensions must be consistent with array size" ))
517
517
end
539
539
# # indexing ##
540
540
541
541
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
543
543
chidx = locate (d, I... )
544
544
idxs = d. indexes[chidx... ]
545
545
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})
626
626
end
627
627
end
628
628
629
- immutable ProductIndices{I,N} <: AbstractArray{Bool, N}
629
+ struct ProductIndices{I,N} <: AbstractArray{Bool, N}
630
630
indices:: I
631
631
sz:: NTuple{N,Int}
632
632
end
633
633
Base. size (P:: ProductIndices ) = P. sz
634
634
# This gets passed to map to avoid breaking propagation of inbounds
635
635
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} =
637
637
Bool ((& )(map (propagate_getindex, P. indices, I)... ))
638
638
639
- immutable MergedIndices{I,N} <: AbstractArray{CartesianIndex{N}, N}
639
+ struct MergedIndices{I,N} <: AbstractArray{CartesianIndex{N}, N}
640
640
indices:: I
641
641
sz:: NTuple{N,Int}
642
642
end
643
643
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} =
645
645
CartesianIndex (map (propagate_getindex, M. indices, I))
646
646
# Additionally, we optimize bounds checking when using MergedIndices as an
647
647
# array index since checking, e.g., A[1:500, 1:500] is *way* faster than
0 commit comments