Skip to content

Commit d493255

Browse files
committed
Add vmapreduce function to resolve #110.
1 parent 0440ba0 commit d493255

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

docs/src/vectorized_convenience_functions.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,22 @@ BenchmarkTools.Trial:
114114
evals/sample: 193
115115
```
116116

117+
## vmapreduce
117118

119+
Vectorized version of `mapreduce`. `vmapreduce(f, op, a, b, c)` applies `f(a[i], b[i], c[i])` for `i in eachindex(a,b,c)`, reducing the results to a scalar with `op`.
120+
121+
```julia
122+
julia> using LoopVectorization, BenchmarkTools
123+
124+
julia> x = rand(127); y = rand(127);
125+
126+
julia> @btime vmapreduce(hypot, +, $x, $y)
127+
191.420 ns (0 allocations: 0 bytes)
128+
96.75538300513509
129+
130+
julia> @btime mapreduce(hypot, +, $x, $y)
131+
1.777 μs (5 allocations: 1.25 KiB)
132+
96.75538300513509
133+
```
118134

119135

src/LoopVectorization.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const NativeTypes = Union{Bool, Base.HWReal}
2626
export LowDimArray, stridedpointer, vectorizable,
2727
@avx, @_avx, *ˡ, _avx_!,
2828
vmap, vmap!, vmapnt, vmapnt!, vmapntt, vmapntt!,
29-
vfilter, vfilter!
29+
vfilter, vfilter!, vmapreduce, vreduce
3030

3131
const VECTORWIDTHSYMBOL, ELTYPESYMBOL = Symbol("##Wvecwidth##"), Symbol("##Tloopeltype##")
3232

@@ -58,6 +58,7 @@ include("condense_loopset.jl")
5858
include("reconstruct_loopset.jl")
5959
include("constructors.jl")
6060
include("user_api_conveniences.jl")
61+
include("mapreduce.jl")
6162

6263
"""
6364
LoopVectorization provides macros and functions that combine SIMD vectorization and

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Base.IndexStyle(::Type{<:FallbackArrayWrapper}) = IndexLinear()
4545

4646
@time include("filter.jl")
4747

48+
@time include("mapreduce.jl")
49+
4850
@time include("ifelsemasks.jl")
4951

5052
@time include("dot.jl")

0 commit comments

Comments
 (0)