Skip to content

Commit 579fcdd

Browse files
authored
Merge pull request #124 from JuliaParallel/anj/bc
Update to broadcast API changes in base
2 parents 05c3c5d + 9303ad3 commit 579fcdd

File tree

5 files changed

+35
-34
lines changed

5 files changed

+35
-34
lines changed

src/darray.jl

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ type DArray{T,N,A} <: AbstractArray{T,N}
5656
end
5757

5858
eltype{T}(::Type{DArray{T}}) = T
59-
empty_localpart(T,N,A) = convert(A, Array(T, ntuple(zero, N)))
59+
empty_localpart(T,N,A) = convert(A, Array{T}(ntuple(zero, N)))
6060

6161
typealias SubDArray{T,N,D<:DArray} SubArray{T,N,D}
6262
typealias SubOrDArray{T,N} Union{DArray{T,N}, SubDArray{T,N}}
@@ -177,14 +177,14 @@ function DArray(refs)
177177
id = next_did()
178178

179179
npids = [r.where for r in refs]
180-
nsizes = Array(Tuple, dimdist)
180+
nsizes = Array{Tuple}(dimdist)
181181
@sync for i in 1:length(refs)
182182
let i=i
183183
@async nsizes[i] = remotecall_fetch(sz_localpart_ref, npids[i], refs[i], id)
184184
end
185185
end
186186

187-
nindexes = Array(NTuple{length(dimdist),UnitRange{Int}}, dimdist...)
187+
nindexes = Array{NTuple{length(dimdist),UnitRange{Int}}}(dimdist...)
188188

189189
for i in 1:length(nindexes)
190190
subidx = ind2sub(dimdist, i)
@@ -231,7 +231,7 @@ DArray(init, d::DArray) = DArray(next_did(), init, size(d), procs(d), d.indexes,
231231

232232
sz_localpart_ref(ref, id) = size(fetch(ref))
233233

234-
Base.similar(d::DArray, T::Type, dims::Dims) = DArray(I->Array(T, map(length,I)), dims, procs(d))
234+
Base.similar(d::DArray, T::Type, dims::Dims) = DArray(I->Array{T}(map(length,I)), dims, procs(d))
235235
Base.similar(d::DArray, T::Type) = similar(d, T, size(d))
236236
Base.similar{T}(d::DArray{T}, dims::Dims) = similar(d, T, dims)
237237
Base.similar{T}(d::DArray{T}) = similar(d, T, size(d))
@@ -284,7 +284,7 @@ end
284284
function chunk_idxs(dims, chunks)
285285
cuts = map(defaultdist, dims, chunks)
286286
n = length(dims)
287-
idxs = Array(NTuple{n,UnitRange{Int}},chunks...)
287+
idxs = Array{NTuple{n,UnitRange{Int}}}(chunks...)
288288
for cidx in CartesianRange(tuple(chunks...))
289289
idxs[cidx.I...] = ntuple(i -> (cuts[i][cidx[i]]:cuts[i][cidx[i] + 1] - 1), n)
290290
end
@@ -456,7 +456,7 @@ end
456456
Base.convert{T,N,S<:AbstractArray}(::Type{DArray{T,N,S}}, A::S) = distribute(convert(AbstractArray{T,N}, A))
457457

458458
Base.convert{S,T,N}(::Type{Array{S,N}}, d::DArray{T,N}) = begin
459-
a = Array(S, size(d))
459+
a = Array{S}(size(d))
460460
@sync begin
461461
for i = 1:length(d.pids)
462462
@async a[d.indexes[i]...] = chunk(d, i)
@@ -475,7 +475,7 @@ Base.convert{S,T,N}(::Type{Array{S,N}}, s::SubDArray{T,N}) = begin
475475
return chunk(d, l...)
476476
end
477477
end
478-
a = Array(S, size(s))
478+
a = Array{S}(size(s))
479479
a[[1:size(a,i) for i=1:N]...] = s
480480
return a
481481
end
@@ -484,7 +484,7 @@ function Base.convert{T,N}(::Type{DArray}, SD::SubArray{T,N})
484484
D = SD.parent
485485
DArray(size(SD), procs(D)) do I
486486
TR = typeof(SD.indexes[1])
487-
lindices = Array(TR, 0)
487+
lindices = Array{TR}(0)
488488
for (i,r) in zip(I, SD.indexes)
489489
st = step(r)
490490
lrstart = first(r) + st*(first(i)-1)
@@ -508,7 +508,7 @@ Base.reshape{T,S<:Array}(A::DArray{T,1,S}, d::Dims) = begin
508508
d1offs = first(I[1])
509509
nd = length(I)
510510

511-
B = Array(T,sz)
511+
B = Array{T}(sz)
512512
nr = size(B,1)
513513
sztail = size(B)[2:end]
514514

@@ -667,16 +667,17 @@ import Base: checkbounds_indices
667667
# the local portion of the source array
668668
function Base.setindex!(a::Array, s::SubDArray,
669669
I::Union{UnitRange{Int},Colon,Vector{Int},StepRange{Int,Int}}...)
670-
Base.setindex_shape_check(s, Base.index_lengths(a, I...)...)
671-
n = length(I)
670+
Inew = Base.to_indices(a, I)
671+
Base.setindex_shape_check(s, Base.index_lengths(Inew...)...)
672+
n = length(Inew)
672673
d = s.parent
673-
J = Base.decolon(d, s.indexes...)
674+
J = Base.to_indices(d, s.indexes)
674675
@sync for i = 1:length(d.pids)
675676
K_c = d.indexes[i]
676677
K = map(intersect, J, K_c)
677678
if !any(isempty, K)
678679
K_mask = map(indexin_mask, J, K_c)
679-
idxs = restrict_indices(Base.decolon(a, I...), K_mask)
680+
idxs = restrict_indices(Inew, K_mask)
680681
if isequal(K, K_c)
681682
# whole chunk
682683
@async a[idxs...] = chunk(d, i)

src/linalg.jl

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

99
function Base.transpose{T}(D::DArray{T,2})
1010
DArray(reverse(size(D)), procs(D)) do I
11-
lp = Array(T, map(length, I))
11+
lp = Array{T}(map(length, I))
1212
rp = convert(Array, D[reverse(I)...])
1313
transpose!(lp, rp)
1414
end
@@ -91,7 +91,7 @@ function A_mul_B!(α::Number, A::DMatrix, x::AbstractVector, β::Number, y::DVec
9191
end
9292

9393
# Multiply on each tile of A
94-
R = Array(Future, size(A.pids)...)
94+
R = Array{Future}(size(A.pids)...)
9595
for j = 1:size(A.pids, 2)
9696
xj = x[A.cuts[2][j]:A.cuts[2][j + 1] - 1]
9797
for i = 1:size(A.pids, 1)
@@ -135,7 +135,7 @@ function Ac_mul_B!(α::Number, A::DMatrix, x::AbstractVector, β::Number, y::DVe
135135
end
136136

137137
# Multiply on each tile of A
138-
R = Array(Future, reverse(size(A.pids))...)
138+
R = Array{Future}(reverse(size(A.pids))...)
139139
for j = 1:size(A.pids, 1)
140140
xj = x[A.cuts[1][j]:A.cuts[1][j + 1] - 1]
141141
for i = 1:size(A.pids, 2)
@@ -201,9 +201,9 @@ function _matmatmul!(α::Number, A::DMatrix, B::AbstractMatrix, β::Number, C::D
201201

202202
# Multiply on each tile of A
203203
if tA == 'N'
204-
R = Array(Future, size(procs(A))..., size(procs(C), 2))
204+
R = Array{Future}(size(procs(A))..., size(procs(C), 2))
205205
else
206-
R = Array(Future, reverse(size(procs(A)))..., size(procs(C), 2))
206+
R = Array{Future}(reverse(size(procs(A)))..., size(procs(C), 2))
207207
end
208208
for j = 1:size(A.pids, Ad2)
209209
for k = 1:size(C.pids, 2)
@@ -258,12 +258,12 @@ _matmul_op = (t,s) -> t*s + t*s
258258

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

273273
function Ac_mul_B(A::DMatrix, x::AbstractVector)
274274
T = Base.promote_op(_matmul_op, eltype(A), eltype(x))
275-
y = DArray(I -> Array(T, map(length, I)),
275+
y = DArray(I -> Array{T}(map(length, I)),
276276
(size(A, 2),),
277277
procs(A)[1,:],
278278
(size(procs(A), 2),))
279279
return Ac_mul_B!(one(T), A, x, zero(T), y)
280280
end
281281
function Ac_mul_B(A::DMatrix, B::AbstractMatrix)
282282
T = Base.promote_op(_matmul_op, eltype(A), eltype(B))
283-
C = DArray(I -> Array(T, map(length, I)), (size(A, 2),
283+
C = DArray(I -> Array{T}(map(length, I)), (size(A, 2),
284284
size(B, 2)),
285285
procs(A)[1:min(size(procs(A), 1), size(procs(B), 2)),:],
286286
(size(procs(A), 2), min(size(procs(A), 1), size(procs(B), 2))))

src/mapreduce.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Base.map!{F}(f::F, dest::DArray, src::DArray) = begin
99
return dest
1010
end
1111

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

1414
Base.Broadcast.promote_containertype(::Type{DArray}, ::Type{DArray}) = DArray
1515
Base.Broadcast.promote_containertype(::Type{DArray}, ::Type{Array}) = DArray
@@ -131,7 +131,7 @@ Base.mapreducedim(f, op, R::DArray, A::DArray) = begin
131131
end
132132

133133
function nnz(A::DArray)
134-
B = Array(Any, size(A.pids))
134+
B = Array{Any}(size(A.pids))
135135
@sync begin
136136
for i in eachindex(A.pids)
137137
@async B[i...] = remotecall_fetch(x -> nnz(localpart(x)), A.pids[i...], A)
@@ -301,7 +301,7 @@ function _ppeval(f, A...; dim = map(ndims, A))
301301
push!(ridx, 1)
302302
Rsize = map(last, ridx)
303303
Rsize[end] = dimlength
304-
R = Array(eltype(R1), Rsize...)
304+
R = Array{eltype(R1)}(Rsize...)
305305

306306
for i = 1:dimlength
307307
for j = 1:narg

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{T}(d, myidx, refs::Array{RemoteChannel}, boun
3838
end
3939

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

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

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

129129
@assert lb<=ub
130130

131-
s = Array(T, np)
131+
s = Array{T}(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{T}(d::DVector{T}; sample=true, kwargs...)
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}(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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ end
343343
check_leaks(t)
344344

345345
t=@testset "test max / min / sum" begin
346-
a = map(x -> Int(round(rand() * 100)) - 50, Array(Int, 100,1000))
346+
a = map(x -> Int(round(rand() * 100)) - 50, Array{Int}(100,1000))
347347
d = distribute(a)
348348

349349
@test sum(d) == sum(a)
@@ -359,7 +359,7 @@ end
359359
check_leaks(t)
360360

361361
t=@testset "test all / any" begin
362-
a = map(x->Int(round(rand() * 100)) - 50, Array(Int, 100,1000))
362+
a = map(x->Int(round(rand() * 100)) - 50, Array{Int}(100,1000))
363363
a = [true for i in 1:100]
364364
d = distribute(a)
365365

@@ -752,9 +752,9 @@ t=@testset "test scalar ops" begin
752752
@test @eval ($f)($a, $a) == ($f)($b, $b)
753753
end
754754

755-
@testset "$f" for f in (rem,)
755+
@testset "$f" for f in (:rem,)
756756
x = rand()
757-
@test f(a, x) == f(b, x)
757+
@test @eval ($f).($a, $x) == ($f).($b, $x)
758758
end
759759
close(a)
760760
close(c)

0 commit comments

Comments
 (0)