@@ -6,40 +6,30 @@ function test_mapreduce(AT)
6
6
range = ET <: Integer ? (ET (- 2 ): ET (2 )) : ET
7
7
@testset " mapreducedim" begin
8
8
for N in (2 , 10 )
9
- y = rand (range, N, N)
10
- x = T (y)
11
- @test sum (y, dims = 2 ) ≈ Array (sum (x, dims = 2 ))
12
- @test sum (y, dims = 1 ) ≈ Array (sum (x, dims = 1 ))
13
- @test sum (y, dims = (1 , 2 )) ≈ Array (sum (x, dims = (1 , 2 )))
9
+ @test compare (x -> sum (x, dims= 2 ), AT, rand (range, N, N))
10
+ @test compare (x -> sum (x, dims= 1 ), AT, rand (range, N, N))
11
+ @test compare (x -> sum (x, dims= (1 , 2 )), AT, rand (range, N, N))
14
12
15
- y = rand (range, N, 10 )
16
- x = T (y)
17
- @test sum (y, dims = 2 ) ≈ Array (sum (x, dims = 2 ))
18
- @test sum (y, dims = 1 ) ≈ Array (sum (x, dims = 1 ))
13
+ @test compare (x -> sum (x, dims= 2 ), AT, rand (range, N, 10 ))
14
+ @test compare (x -> sum (x, dims= 1 ), AT, rand (range, N, 10 ))
19
15
20
- y = rand (range, 10 , N)
21
- x = T (y)
22
- @test sum (y, dims = 2 ) ≈ Array (sum (x, dims = 2 ))
23
- @test sum (y, dims = 1 ) ≈ Array (sum (x, dims = 1 ))
16
+ @test compare (x -> sum (x, dims= 2 ), AT, rand (range, 10 , N))
17
+ @test compare (x -> sum (x, dims= 1 ), AT, rand (range, 10 , N))
24
18
25
- y = rand (range, N, N)
26
- x = T (y)
27
19
_zero = zero (ET)
28
20
_addone (z) = z + one (z)
29
- @test mapreduce (_addone, + , y ; dims = 2 , init = _zero) ≈
30
- Array ( mapreduce (_addone, + , x; dims = 2 , init = _zero ))
31
- @test mapreduce (_addone, + , y; init = _zero) ≈
32
- mapreduce (_addone, + , x; init = _zero )
21
+ @test compare (x -> mapreduce (_addone, + , x ; dims = 2 ),
22
+ AT, rand (range, N, N ))
23
+ @test compare (x -> mapreduce (_addone, + , x; dims = 2 , init = _zero),
24
+ AT, rand (range, N, N) )
33
25
end
34
26
end
35
27
@testset " sum maximum minimum prod" begin
36
28
for dims in ((4048 ,), (1024 ,1024 ), (77 ,), (1923 ,209 ))
37
- Ac = rand (range, dims)
38
- A = T (Ac)
39
- @test sum (A) ≈ sum (Ac)
40
- ET <: Complex || @test maximum (A) ≈ maximum (Ac)
41
- ET <: Complex || @test minimum (A) ≈ minimum (Ac)
42
- @test prod (A) ≈ prod (Ac)
29
+ @test compare (sum, AT, rand (range, dims))
30
+ @test compare (prod, AT, rand (range, dims))
31
+ ET <: Complex || @test compare (maximum, AT,rand (range, dims))
32
+ ET <: Complex || @test compare (minimum, AT,rand (range, dims))
43
33
end
44
34
end
45
35
end
0 commit comments