@@ -14,7 +14,7 @@ vec_vreduce(op, v::Vec{1}) = VectorizationBase.extractelement(v, 0)
14
14
a
15
15
end
16
16
17
- function mapreduce_simple (f:: F , op:: OP , args:: Vararg{DenseNativeArray ,A} ) where {F,OP,A}
17
+ function mapreduce_simple (f:: F , op:: OP , args:: Vararg{AbstractArray ,A} ) where {F,OP,A}
18
18
ptrargs = ntuple (a -> pointer (args[a]), Val (A))
19
19
N = length (first (args))
20
20
iszero (N) && throw (" Length of vector is 0!" )
32
32
33
33
Vectorized version of `mapreduce`. Applies `f` to each element of the arrays `A`, and reduces the result with `op`.
34
34
"""
35
- @inline function vmapreduce (f:: F , op:: OP , arg1:: DenseArray{T} , args:: Vararg{DenseArray{T},A} ) where {F,OP,T<: NativeTypes ,A}
35
+ @inline function vmapreduce (f:: F , op:: OP , arg1:: AbstractArray{T} , args:: Vararg{AbstractArray{T},A} ) where {F,OP,T<: NativeTypes ,A}
36
+ if ! (check_args (args1, args... ) && all_dense (arg1, args... ))
37
+ return mapreduce (f, op, arg1, args... )
38
+ end
36
39
N = length (arg1)
37
40
iszero (A) || @assert all (length .(args) .== N)
38
41
W = VectorizationBase. pick_vector_width (T)
@@ -43,7 +46,7 @@ Vectorized version of `mapreduce`. Applies `f` to each element of the arrays `A`
43
46
_vmapreduce (f, op, V, N, T, arg1, args... )
44
47
end
45
48
end
46
- @inline function _vmapreduce (f:: F , op:: OP , :: StaticInt{W} , N, :: Type{T} , args:: Vararg{DenseArray {<:NativeTypes},A} ) where {F,OP,A,W,T}
49
+ @inline function _vmapreduce (f:: F , op:: OP , :: StaticInt{W} , N, :: Type{T} , args:: Vararg{AbstractArray {<:NativeTypes},A} ) where {F,OP,A,W,T}
47
50
ptrargs = VectorizationBase. zero_offsets .(stridedpointer .(args))
48
51
if N ≥ 4 W
49
52
index = VectorizationBase. Unroll {1,1,4,1,W,0x0000000000000000} ((Zero (),)); i = 4 W
@@ -79,6 +82,9 @@ Vectorized version of `reduce`. Reduces the array `A` using the operator `op`.
79
82
80
83
for (op, init) in zip ((:+ , :max , :min ), (:zero , :typemin , :typemax ))
81
84
@eval @inline function vreduce (:: typeof ($ op), arg; dims = nothing )
85
+ if ! (check_args (arg) && all_dense (arg))
86
+ return reduce ($ op, arg, dims = dims)
87
+ end
82
88
isnothing (dims) && return _vreduce ($ op, arg)
83
89
isone (ndims (arg)) && return [_vreduce ($ op, arg)]
84
90
@assert length (dims) == 1
0 commit comments