1
1
# # higher-order functions ##
2
2
3
- # ## We need to define broadcast operations which will soon be very common
4
- # ## in base through the dot-verctorization syntax
5
-
6
3
Base. map (f, d:: DArray ) = DArray (I-> map (f, localpart (d)), d)
7
4
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
+
8
15
function Base. reduce (f, d:: DArray )
9
16
results= []
10
17
@sync begin
@@ -30,13 +37,6 @@ Base.mapreduce(f, opt::Union{typeof(|), typeof(&)}, d::DArray) = _mapreduce(f, o
30
37
Base. mapreduce (f, opt:: Function , d:: DArray ) = _mapreduce (f, opt, d)
31
38
Base. mapreduce (f, opt, d:: DArray ) = _mapreduce (f, opt, d)
32
39
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
-
40
40
# mapreducedim
41
41
Base. reducedim_initarray {R} (A:: DArray , region, v0, :: Type{R} ) = begin
42
42
# Store reduction on lowest pids
@@ -146,6 +146,9 @@ for (fn, fr) in ((:any, :|),
146
146
end
147
147
end
148
148
149
+ # Unary vector functions
150
+ (- )(D:: DArray ) = map (- , D)
151
+
149
152
# scalar ops
150
153
(+ )(A:: DArray{Bool} , x:: Bool ) = A .+ x
151
154
(+ )(x:: Bool , A:: DArray{Bool} ) = x .+ A
@@ -225,22 +228,6 @@ for f in (:.+, :.-, :.*, :./, :.%, :.<<, :.>>)
225
228
end
226
229
end
227
230
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
-
244
231
function mapslices {T,N,A} (f:: Function , D:: DArray{T,N,A} , dims:: AbstractVector )
245
232
if ! all (t -> t == 1 , size (D. indexes)[dims])
246
233
p = ones (Int, ndims (D))
0 commit comments