Skip to content

Commit 1a4aa62

Browse files
committed
fix tests?
1 parent 7a66328 commit 1a4aa62

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/mapreduce.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ reduce(::typeof(hcat), A::StaticArray{<:Tuple,<:StaticVecOrMatLike}) =
213213
_mapreduce(identity, op, dims, init, Size(a), a)
214214

215215
@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))
216+
b = _reduce(op, a, first(dims))
217+
return _reduce(op, b, Base.tail(dims), init)
218218
end
219219
_reduce(op, a::StaticArray, dims::Tuple{}, ::_InitialValue) = a
220220
_reduce(op, a::StaticArray, dims::Tuple{}, init) = op.(init, a)

test/mapreduce.jl

+8
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,24 @@ using Statistics: mean
3737
v2 = [4,3,2,1]; sv2 = SVector{4}(v2)
3838
@test reduce(+, sv1) === reduce(+, v1)
3939
@test reduce(+, sv1; init=0) === reduce(+, v1; init=0)
40+
@test reduce(+, sv1; init=99) === reduce(+, v1; init=99)
4041
@test reduce(max, sa; dims=Val(1), init=-1.) === SMatrix{1,J}(reduce(max, a, dims=1, init=-1.))
4142
@test reduce(max, sa; dims=1, init=-1.) === SMatrix{1,J}(reduce(max, a, dims=1, init=-1.))
4243
@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)))
4346
@test mapreduce(-, +, sv1) === mapreduce(-, +, v1)
4447
@test mapreduce(-, +, sv1; init=0) === mapreduce(-, +, v1, init=0)
4548
@test mapreduce(*, +, sv1, sv2) === 40
4649
@test mapreduce(*, +, sv1, sv2; init=0) === 40
4750
@test mapreduce(x->x^2, max, sa; dims=Val(1), init=-1.) == SMatrix{1,J}(mapreduce(x->x^2, max, a, dims=1, init=-1.))
4851
@test mapreduce(x->x^2, max, sa; dims=1, init=-1.) == SMatrix{1,J}(mapreduce(x->x^2, max, a, dims=1, init=-1.))
4952
@test mapreduce(x->x^2, max, sa; dims=2, init=-1.) == SMatrix{I,1}(mapreduce(x->x^2, max, a, dims=2, init=-1.))
53+
54+
# Zero-dim array
55+
a0 = fill(rand()); sa0 = SArray{Tuple{}}(a0)
56+
@test reduce(+, sa0) === reduce(+, a0)
57+
@test reduce(/, sa0, dims=(), init=1.2) === SArray{Tuple{}}(reduce(/, a0, dims=(), init=1.2))
5058
end
5159

5260
@testset "[map]foldl" begin

0 commit comments

Comments
 (0)