Skip to content

Commit 9018902

Browse files
authored
Merge pull request #106 from JuliaParallel/anj/bcast
Define broadcast and delete vectorized scalar function definitions
2 parents 01b6cf5 + 9969e7e commit 9018902

File tree

2 files changed

+15
-28
lines changed

2 files changed

+15
-28
lines changed

src/mapreduce.jl

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
## higher-order functions ##
22

3-
### We need to define broadcast operations which will soon be very common
4-
### in base through the dot-verctorization syntax
5-
63
Base.map(f, d::DArray) = DArray(I->map(f, localpart(d)), d)
74

5+
Base.map!{F}(f::F, d::DArray) = begin
6+
@sync for p in procs(d)
7+
@async remotecall_fetch((f,d)->(map!(f, localpart(d)); nothing), p, f, d)
8+
end
9+
return d
10+
end
11+
12+
# FixMe! We'll have to handle the general n args case but it seems tricky
13+
Base.broadcast(f, d::DArray) = DArray(I -> broadcast(f, localpart(d)), d)
14+
815
function Base.reduce(f, d::DArray)
916
results=[]
1017
@sync begin
@@ -30,13 +37,6 @@ Base.mapreduce(f, opt::Union{typeof(|), typeof(&)}, d::DArray) = _mapreduce(f, o
3037
Base.mapreduce(f, opt::Function, d::DArray) = _mapreduce(f, opt, d)
3138
Base.mapreduce(f, opt, d::DArray) = _mapreduce(f, opt, d)
3239

33-
Base.map!{F}(f::F, d::DArray) = begin
34-
@sync for p in procs(d)
35-
@async remotecall_fetch((f,d)->(map!(f, localpart(d)); nothing), p, f, d)
36-
end
37-
return d
38-
end
39-
4040
# mapreducedim
4141
Base.reducedim_initarray{R}(A::DArray, region, v0, ::Type{R}) = begin
4242
# Store reduction on lowest pids
@@ -146,6 +146,9 @@ for (fn, fr) in ((:any, :|),
146146
end
147147
end
148148

149+
# Unary vector functions
150+
(-)(D::DArray) = map(-, D)
151+
149152
# scalar ops
150153
(+)(A::DArray{Bool}, x::Bool) = A .+ x
151154
(+)(x::Bool, A::DArray{Bool}) = x .+ A
@@ -225,22 +228,6 @@ for f in (:.+, :.-, :.*, :./, :.%, :.<<, :.>>)
225228
end
226229
end
227230

228-
### Should be deleted when broadcast is defined
229-
for f in (:-, :abs, :abs2, :acos, :acosd, :acosh, :acot, :acotd, :acoth,
230-
:acsc, :acscd, :acsch, :angle, :asec, :asecd, :asech, :asin,
231-
:asind, :asinh, :atan, :atand, :atanh, :big, :cbrt, :ceil, :cis,
232-
:complex, :cos, :cosc, :cosd, :cosh, :cospi, :cot, :cotd, :coth,
233-
:csc, :cscd, :csch, :dawson, :deg2rad, :digamma, :erf, :erfc,
234-
:erfcinv, :erfcx, :erfi, :erfinv, :exp, :exp10, :exp2, :expm1,
235-
:exponent, :float, :floor, :gamma, :imag, :invdigamma, :isfinite,
236-
:isinf, :isnan, :lfact, :lgamma, :log, :log10, :log1p, :log2, :rad2deg,
237-
:real, :sec, :secd, :sech, :sign, :sin, :sinc, :sind, :sinh, :sinpi,
238-
:sqrt, :tan, :tand, :tanh, :trigamma)
239-
@eval begin
240-
($f)(A::DArray) = map($f, A)
241-
end
242-
end
243-
244231
function mapslices{T,N,A}(f::Function, D::DArray{T,N,A}, dims::AbstractVector)
245232
if !all(t -> t == 1, size(D.indexes)[dims])
246233
p = ones(Int, ndims(D))

test/darray.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,12 +670,12 @@ check_leaks()
670670
lgamma, log, log10, log1p, log2, rad2deg, real,
671671
sec, secd, sech, sign, sin, sinc, sind,
672672
sinh, sinpi, sqrt, tan, tand, tanh, trigamma)
673-
@test f(a) == f(b)
673+
@test f.(a) == f.(b)
674674
end
675675
a = a + 1
676676
b = b + 1
677677
@testset "$f" for f in (asec, asecd, acosh, acsc, acscd, acoth)
678-
@test f(a) == f(b)
678+
@test f.(a) == f.(b)
679679
end
680680
close(a)
681681
darray_closeall() # close the temporaries created above

0 commit comments

Comments
 (0)