Skip to content

Commit 4adac67

Browse files
authored
Merge pull request #94 from JuliaParallel/vc/map_localparts
Implement the general case for map_localparts over DArray
2 parents 23c329e + 423ff21 commit 4adac67

File tree

4 files changed

+12
-23
lines changed

4 files changed

+12
-23
lines changed

src/DistributedArrays.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ __precompile__(true)
22

33
module DistributedArrays
44

5-
using Compat
6-
import Compat.view
7-
85
using Primes
96
using Primes: factor
107

src/linalg.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function dot(x::DVector, y::DVector)
4343
@async push!(results, remotecall_fetch((x, y, i) -> dot(localpart(x), fetch(y, i)), x.pids[i], x, y, i))
4444
end
4545
end
46-
return reduce(@functorize(+), results)
46+
return reduce(+, results)
4747
end
4848

4949
function norm(x::DVector, p::Real = 2)

src/mapreduce.jl

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function _mapreduce(f, opt, d::DArray)
2626
end
2727
reduce(opt, results)
2828
end
29-
Base.mapreduce(f, opt::Union{typeof(@functorize(|)), typeof(@functorize(&))}, d::DArray) = _mapreduce(f, opt, d)
29+
Base.mapreduce(f, opt::Union{typeof(|), typeof(&)}, d::DArray) = _mapreduce(f, opt, d)
3030
Base.mapreduce(f, opt::Function, d::DArray) = _mapreduce(f, opt, d)
3131
Base.mapreduce(f, opt, d::DArray) = _mapreduce(f, opt, d)
3232

@@ -124,26 +124,25 @@ for (fn, fr) in ((:sum, :+),
124124
(:minimum, :min),
125125
(:any, :|),
126126
(:all, :&))
127-
@eval (Base.$fn)(d::DArray) = reduce(@functorize($fr), d)
127+
@eval (Base.$fn)(d::DArray) = reduce($fr, d)
128128
end
129129

130130
# mapreduce like
131131
for (fn, fr1, fr2) in ((:maxabs, :abs, :max),
132132
(:minabs, :abs, :min),
133133
(:sumabs, :abs, :+),
134134
(:sumabs2, :abs2, :+))
135-
@eval (Base.$fn)(d::DArray) = mapreduce(@functorize($fr1), @functorize($fr2), d)
135+
@eval (Base.$fn)(d::DArray) = mapreduce($fr1, $fr2, d)
136136
end
137137

138138
# semi mapreduce
139139
for (fn, fr) in ((:any, :|),
140140
(:all, :&),
141141
(:count, :+))
142142
@eval begin
143-
(Base.$fn)(f::typeof(@functorize(identity)), d::DArray) = mapreduce(f, @functorize($fr), d)
144-
(Base.$fn)(f::Base.Predicate, d::DArray) = mapreduce(f, @functorize($fr), d)
145-
# (Base.$fn)(f::Base.Func{1}, d::DArray) = mapreduce(f, @functorize $fr, d)
146-
(Base.$fn)(f::Callable, d::DArray) = mapreduce(f, @functorize($fr), d)
143+
(Base.$fn)(f::typeof(identity), d::DArray) = mapreduce(f, $fr, d)
144+
(Base.$fn)(f::Base.Predicate{1}, d::DArray) = mapreduce(f, $fr, d)
145+
(Base.$fn)(f::Callable, d::DArray) = mapreduce(f, $fr, d)
147146
end
148147
end
149148

@@ -208,17 +207,17 @@ for f in (:+, :-, :div, :mod, :rem, :&, :|, :$)
208207
B = samedist(A, B)
209208
map_localparts($f, A, B)
210209
end
211-
($f){T}(A::DArray{T}, B::Array{T}) = ($f)(A, distribute(B, A))
212-
($f){T}(A::Array{T}, B::DArray{T}) = ($f)(distribute(A, B), B)
210+
($f){T}(A::DArray{T}, B::Array{T}) = map_localparts($f, A, B)
211+
($f){T}(A::Array{T}, B::DArray{T}) = map_localparts($f, A, B)
213212
end
214213
end
215214
for f in (:.+, :.-, :.*, :./, :.%, :.<<, :.>>)
216215
@eval begin
217216
function ($f){T}(A::DArray{T}, B::DArray{T})
218217
map_localparts($f, A, B)
219218
end
220-
($f){T}(A::DArray{T}, B::Array{T}) = ($f)(A, distribute(B, A))
221-
($f){T}(A::Array{T}, B::DArray{T}) = ($f)(distribute(A, B), B)
219+
($f){T}(A::DArray{T}, B::Array{T}) = map_localparts($f, A, B)
220+
($f){T}(A::Array{T}, B::DArray{T}) = map_localparts($f, A, B)
222221
end
223222
end
224223

test/runtests.jl

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
if VERSION >= v"0.5.0-dev+7720"
2-
using Base.Test
3-
else
4-
using BaseTestNext
5-
const Test = BaseTestNext
6-
end
1+
using Base.Test
72

83
# add at least 3 worker processes
94
if nworkers() < 3
@@ -13,8 +8,6 @@ end
138
@assert nprocs() > 3
149
@assert nworkers() >= 3
1510

16-
using Compat
17-
import Compat.view
1811
using DistributedArrays
1912
using StatsBase # for fit(Histogram, ...)
2013
@everywhere using StatsBase # because exported functions are not exported on workers with using

0 commit comments

Comments
 (0)