We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7a66328 commit 22ed75eCopy full SHA for 22ed75e
src/mapreduce.jl
@@ -213,8 +213,8 @@ reduce(::typeof(hcat), A::StaticArray{<:Tuple,<:StaticVecOrMatLike}) =
213
_mapreduce(identity, op, dims, init, Size(a), a)
214
215
@inline function _reduce(op, a::StaticArray, dims::Tuple, init = _InitialValue())
216
- b = _reduce(op, a, first(dims), init)
217
- return _reduce(op, b, Base.tail(dims))
+ b = _reduce(op, a, first(dims))
+ return _reduce(op, b, Base.tail(dims), init)
218
end
219
_reduce(op, a::StaticArray, dims::Tuple{}, ::_InitialValue) = a
220
_reduce(op, a::StaticArray, dims::Tuple{}, init) = op.(init, a)
test/mapreduce.jl
@@ -37,9 +37,12 @@ using Statistics: mean
37
v2 = [4,3,2,1]; sv2 = SVector{4}(v2)
38
@test reduce(+, sv1) === reduce(+, v1)
39
@test reduce(+, sv1; init=0) === reduce(+, v1; init=0)
40
+ @test reduce(+, sv1; init=99) === reduce(+, v1; init=99)
41
@test reduce(max, sa; dims=Val(1), init=-1.) === SMatrix{1,J}(reduce(max, a, dims=1, init=-1.))
42
@test reduce(max, sa; dims=1, init=-1.) === SMatrix{1,J}(reduce(max, a, dims=1, init=-1.))
43
@test reduce(max, sa; dims=2, init=-1.) === SMatrix{I,1}(reduce(max, a, dims=2, init=-1.))
44
+ @test reduce(*, sa; dims=(1,2), init=2.0) === SMatrix{1,1}(reduce(*, a, dims=(1,2), init=2.0))
45
+ @test reduce(*, sa; dims=(), init=(1.0+im)) === SMatrix{I,J}(reduce(*, a, dims=(), init=(1.0+im)))
46
@test mapreduce(-, +, sv1) === mapreduce(-, +, v1)
47
@test mapreduce(-, +, sv1; init=0) === mapreduce(-, +, v1, init=0)
48
@test mapreduce(*, +, sv1, sv2) === 40
0 commit comments