@@ -116,6 +116,9 @@ for (T, suff) in ((Float64, ""), (Float32, "f"))
116
116
Base. copy (bc:: Base.Broadcast.Broadcasted{Style, Axes, typeof($f), Tuple{Array{$T, N}}} ) where {Style, Axes, N} = ($ f)(bc. args... )
117
117
Base. copyto! (dest:: Array{$T, N} , bc:: Base.Broadcast.Broadcasted{Style, Axes, typeof($f), Tuple{Array{$T, N}}} ) where {Style, Axes, N} = ($ f!)(dest, bc. args... )
118
118
end
119
+ if T == Float32
120
+ @eval Base. broadcasted (:: typeof ($ f), arg:: Union{Array{F,N},Base.Broadcast.Broadcasted} ) where {N,F<: Union{Float32,Float64} } = ($ f)(maybecopy (arg))
121
+ end
119
122
end
120
123
for (f, fa) in (twoarg_funcs... ,(:pow ,:pow ))
121
124
f! = Symbol (" $(f) !" )
@@ -124,14 +127,19 @@ for (T, suff) in ((Float64, ""), (Float32, "f"))
124
127
Base. copy (bc:: Base.Broadcast.Broadcasted{Style, Axes, typeof($f), Tuple{Array{$T, N},Array{$T,N}}} ) where {Style, Axes, N} = ($ f)(bc. args... )
125
128
Base. copyto! (dest:: Array{$T, N} , bc:: Base.Broadcast.Broadcasted{Style, Axes, typeof($f), Tuple{Array{$T,N},Array{$T,N}}} ) where {Style, Axes, N} = ($ f!)(dest, bc. args... )
126
129
end
130
+ if T == Float32
131
+ @eval Base. broadcasted (:: typeof ($ f), arg1:: Union{Array{F, N},Base.Broadcast.Broadcasted} , arg2:: Union{Array{F, N},Base.Broadcast.Broadcasted} ) where {N,F<: Union{Float32,Float64} } = ($ f)(maybecopy (arg1), maybecopy (arg2))
132
+ end
127
133
end
128
134
end
129
135
130
136
# Functions over single vectors that return scalars/tuples
131
137
for (T, suff) in ((Float32, " " ), (Float64, " D" ))
132
138
133
139
for (f, fa) in ((:maximum , :maxv ), (:minimum , :minv ), (:mean , :meanv ),
134
- (:meansqr , :measqv ), (:meanmag , :meamgv ), (:sum , :sve ))
140
+ (:meanmag , :meamgv ), (:meansqr , :measqv ), (:meanssqr , :mvessq ),
141
+ (:sum , :sve ), (:summag , :svemg ), (:sumsqr , :svesq ),
142
+ (:sumssqr , :svs ))
135
143
@eval begin
136
144
function ($ f)(X:: Vector{$T} )
137
145
val = Ref {$T} (0.0 )
@@ -192,7 +200,133 @@ for (T, suff) in ((Float32, ""), (Float64, "D"))
192
200
return result
193
201
end
194
202
end
203
+
204
+ @eval begin
205
+ # Broadcasting override such that f.(X) turns into f(X)
206
+ Base. copy (bc:: Base.Broadcast.Broadcasted{Style, Axes, typeof($f), Tuple{Array{$T, N},Array{$T,N}}} ) where {Style, Axes, N} = ($ f)(bc. args... )
207
+ Base. copyto! (dest:: Array{$T, N} , bc:: Base.Broadcast.Broadcasted{Style, Axes, typeof($f), Tuple{Array{$T,N},Array{$T,N}}} ) where {Style, Axes, N} = ($ f!)(dest, bc. args... )
208
+ Base. broadcasted (:: typeof ($ f), arg1:: Union{Array{$T, N},Base.Broadcast.Broadcasted} , arg2:: Union{Array{$T, N},Base.Broadcast.Broadcasted} ) where {N} = ($ f)(maybecopy (arg1), maybecopy (arg2))
209
+ end
195
210
end
196
211
end
197
212
213
+ # Element-wise operations over a vector and a scalar
214
+ for (T, suff) in ((Float32, " " ), (Float64, " D" ))
215
+
216
+ for (f, name) in ((:vsadd , " addition" ), (:vsdiv , " division" ), (:vsmul , " multiplication" ))
217
+ f! = Symbol (" $(f) !" )
218
+
219
+ @eval begin
220
+ @doc """
221
+ `$($ f!) (result::Vector{$($ T) }, X::Vector{$($ T) }, c::$($ T) )`
222
+
223
+ Implements vector-scalar **$($ name) ** over **Vector{$($ T) }** and $($ T) and overwrites
224
+ the result vector with computed value. *Returns:* **Vector{$($ T) }** `result`
225
+ """ ->
226
+ function ($ f!)(result:: Vector{$T} , X:: Vector{$T} , c:: $T )
227
+ ccall (($ (string (" vDSP_" , f, suff), libacc)), Cvoid,
228
+ (Ptr{$ T}, Int64, Ptr{$ T}, Ptr{$ T}, Int64, UInt64),
229
+ X, 1 , Ref (c), result, 1 , length (result))
230
+ return result
231
+ end
232
+ end
233
+
234
+ @eval begin
235
+ @doc """
236
+ `$($ f) (X::Vector{$($ T) }, c::$($ T) )`
237
+
238
+ Implements vector-scalar **$($ name) ** over **Vector{$($ T) }** and $($ T) . Allocates
239
+ memory to store result. *Returns:* **Vector{$($ T) }**
240
+ """ ->
241
+ function ($ f)(X:: Vector{$T} , c:: $T )
242
+ result = similar (X)
243
+ ($ f!)(result, X, c)
244
+ return result
245
+ end
246
+ end
247
+ end
248
+ f = :vssub
249
+ f! = Symbol (" $(f) !" )
250
+
251
+ @eval begin
252
+ @doc """
253
+ `$($ f!) (result::Vector{$($ T) }, X::Vector{$($ T) }, c::$($ T) )`
254
+
255
+ Implements vector-scalar **subtraction** over **Vector{$($ T) }** and $($ T) and overwrites
256
+ the result vector with computed value. *Returns:* **Vector{$($ T) }** `result`
257
+ """ ->
258
+ function ($ f!)(result:: Vector{$T} , X:: Vector{$T} , c:: $T )
259
+ ccall (($ (string (" vDSP_vsadd" , suff), libacc)), Cvoid,
260
+ (Ptr{$ T}, Int64, Ptr{$ T}, Ptr{$ T}, Int64, UInt64),
261
+ X, 1 , Ref (- c), result, 1 , length (result))
262
+ return result
263
+ end
264
+ end
265
+
266
+ @eval begin
267
+ @doc """
268
+ `$($ f) (X::Vector{$($ T) }, c::$($ T) )`
269
+
270
+ Implements vector-scalar **subtraction** over **Vector{$($ T) }** and $($ T) . Allocates
271
+ memory to store result. *Returns:* **Vector{$($ T) }**
272
+ """ ->
273
+ function ($ f)(X:: Vector{$T} , c:: $T )
274
+ result = similar (X)
275
+ ($ f!)(result, X, c)
276
+ return result
277
+ end
278
+ end
279
+
280
+ f = :svsub
281
+ f! = Symbol (" $(f) !" )
282
+
283
+ @eval begin
284
+ @doc """
285
+ `$($ f!) (result::Vector{$($ T) }, X::Vector{$($ T) }, c::$($ T) )`
286
+
287
+ Implements vector-scalar **subtraction** over $($ T) and **Vector{$($ T) }** and overwrites
288
+ the result vector with computed value. *Returns:* **Vector{$($ T) }** `result`
289
+ """ ->
290
+ function ($ f!)(result:: Vector{$T} , X:: Vector{$T} , c:: $T )
291
+ ccall (($ (string (" vDSP_vsadd" , suff), libacc)), Cvoid,
292
+ (Ptr{$ T}, Int64, Ptr{$ T}, Ptr{$ T}, Int64, UInt64),
293
+ - X, 1 , Ref (c), result, 1 , length (result))
294
+ return result
295
+ end
296
+ end
297
+
298
+ @eval begin
299
+ @doc """
300
+ `$($ f) (X::Vector{$($ T) , c::$($ T) })`
301
+
302
+ Implements vector-scalar **subtraction** over $($ T) and **Vector{$($ T) }**. Allocates
303
+ memory to store result. *Returns:* **Vector{$($ T) }**
304
+ """ ->
305
+ function ($ f)(X:: Vector{$T} , c:: $T )
306
+ result = similar (X)
307
+ ($ f!)(result, X, c)
308
+ return result
309
+ end
310
+ end
311
+
312
+ for f in (:vsadd , :vssub , :vsdiv , :vsmul )
313
+ f! = Symbol (" $(f) !" )
314
+ @eval begin
315
+ # Broadcasting override such that f.(X) turns into f(X)
316
+ Base. copy (bc:: Base.Broadcast.Broadcasted{Style, Axes, typeof($f), Tuple{Array{$T, N},$T}} ) where {Style, Axes, N} = ($ f)(bc. args... )
317
+ Base. copyto! (dest:: Array{$T, N} , bc:: Base.Broadcast.Broadcasted{Style, Axes, typeof($f), Tuple{Array{$T,N},$T}} ) where {Style, Axes, N} = ($ f!)(dest, bc. args... )
318
+ Base. broadcasted (:: typeof ($ f), arg1:: Union{Array{$T, N},Base.Broadcast.Broadcasted} , arg2:: $T ) where {N} = ($ f)(maybecopy (arg1), arg2)
319
+ end
320
+ end
321
+
322
+ f = :svsub
323
+ f! = Symbol (" $(f) !" )
324
+
325
+ @eval begin
326
+ # Broadcasting override such that f.(X) turns into f(X)
327
+ Base. copy (bc:: Base.Broadcast.Broadcasted{Style, Axes, typeof($f), Tuple{Array{$T, N}, $T}} ) where {Style, Axes, N} = ($ f)(bc. args... )
328
+ Base. copyto! (dest:: Array{$T, N} , bc:: Base.Broadcast.Broadcasted{Style, Axes, typeof($f), Tuple{Array{$T,N}, $T}} ) where {Style, Axes, N} = ($ f!)(dest, bc. args... )
329
+ Base. broadcasted (:: typeof ($ f), arg1:: Union{Array{$T, N},Base.Broadcast.Broadcasted} , arg2:: $T ) where {N} = ($ f)(maybecopy (arg1), arg2)
330
+ end
331
+ end
198
332
0 commit comments