@@ -37,16 +37,24 @@ using Statistics: mean
37
37
v2 = [4 ,3 ,2 ,1 ]; sv2 = SVector {4} (v2)
38
38
@test reduce (+ , sv1) === reduce (+ , v1)
39
39
@test reduce (+ , sv1; init= 0 ) === reduce (+ , v1; init= 0 )
40
+ @test reduce (+ , sv1; init= 99 ) === reduce (+ , v1; init= 99 )
40
41
@test reduce (max, sa; dims= Val (1 ), init= - 1. ) === SMatrix {1,J} (reduce (max, a, dims= 1 , init= - 1. ))
41
42
@test reduce (max, sa; dims= 1 , init= - 1. ) === SMatrix {1,J} (reduce (max, a, dims= 1 , init= - 1. ))
42
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)))
43
46
@test mapreduce (- , + , sv1) === mapreduce (- , + , v1)
44
47
@test mapreduce (- , + , sv1; init= 0 ) === mapreduce (- , + , v1, init= 0 )
45
48
@test mapreduce (* , + , sv1, sv2) === 40
46
49
@test mapreduce (* , + , sv1, sv2; init= 0 ) === 40
47
50
@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. ))
48
51
@test mapreduce (x-> x^ 2 , max, sa; dims= 1 , init= - 1. ) == SMatrix {1,J} (mapreduce (x-> x^ 2 , max, a, dims= 1 , init= - 1. ))
49
52
@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 ))
50
58
end
51
59
52
60
@testset " [map]foldl" begin
0 commit comments