@@ -458,17 +458,47 @@ end
458
458
for R in (fill (0 , 4 ), fill (0 , 4 , 1 ), fill (0 , 4 , 1 , 1 ))
459
459
@test @inferred (maximum! (R, B)) == reshape (21 : 24 , size (R))
460
460
@test @inferred (minimum! (R, B)) == reshape (1 : 4 , size (R))
461
+ @test @inferred (extrema! (fill ((0 ,0 ), size (R)), B)) == reshape (tuple .(1 : 4 , 21 : 24 ), size (R))
461
462
end
462
463
for R in (fill (0 , 1 , 3 ), fill (0 , 1 , 3 , 1 ))
463
464
@test @inferred (maximum! (R, B)) == reshape (16 : 4 : 24 , size (R))
464
465
@test @inferred (minimum! (R, B)) == reshape (1 : 4 : 9 , size (R))
466
+ @test @inferred (extrema! (fill ((0 ,0 ), size (R)), B)) == reshape (tuple .(1 : 4 : 9 , 16 : 4 : 24 ), size (R))
467
+ end
468
+ for (ini, f!) in zip ((0 ,0 ,(0 ,0 )), (maximum!, minimum!, extrema!))
469
+ @test_throws DimensionMismatch f! (fill (ini, 4 , 1 , 1 , 1 ), B)
470
+ @test_throws DimensionMismatch f! (fill (ini, 1 , 3 , 1 , 1 ), B)
471
+ @test_throws DimensionMismatch f! (fill (ini, 1 , 1 , 2 , 1 ), B)
472
+ end
473
+ end
474
+
475
+ function unordered_test_for_extrema (a; dims_test = ((), 1 , 2 , (1 ,2 ), 3 ))
476
+ for dims in dims_test
477
+ vext = extrema (a; dims)
478
+ vmin, vmax = minimum (a; dims), maximum (a; dims)
479
+ @test isequal (extrema! (copy (vext), a), vext)
480
+ @test all (x -> isequal (x[1 ], x[2 : 3 ]), zip (vext,vmin,vmax))
481
+ end
482
+ end
483
+ @testset " 0.0,-0.0 test for extrema with dims" begin
484
+ @test extrema ([- 0.0 ;0.0 ], dims = 1 )[1 ] === (- 0.0 ,0.0 )
485
+ @test tuple (extrema ([- 0.0 ;0.0 ], dims = 2 )... ) === ((- 0.0 , - 0.0 ), (0.0 , 0.0 ))
486
+ end
487
+ @testset " NaN/missing test for extrema with dims #43599" begin
488
+ for sz = (3 , 10 , 100 )
489
+ for T in (Int, BigInt, Float64, BigFloat)
490
+ Aₘ = Matrix {Union{T, Missing}} (rand (- sz: sz, sz, sz))
491
+ Aₘ[rand (1 : sz* sz, sz)] .= missing
492
+ unordered_test_for_extrema (Aₘ)
493
+ if T <: AbstractFloat
494
+ Aₙ = map (i -> ismissing (i) ? T (NaN ) : i, Aₘ)
495
+ unordered_test_for_extrema (Aₙ)
496
+ p = rand (1 : sz* sz, sz)
497
+ Aₘ[p] .= NaN
498
+ unordered_test_for_extrema (Aₘ)
499
+ end
500
+ end
465
501
end
466
- @test_throws DimensionMismatch maximum! (fill (0 , 4 , 1 , 1 , 1 ), B)
467
- @test_throws DimensionMismatch minimum! (fill (0 , 4 , 1 , 1 , 1 ), B)
468
- @test_throws DimensionMismatch maximum! (fill (0 , 1 , 3 , 1 , 1 ), B)
469
- @test_throws DimensionMismatch minimum! (fill (0 , 1 , 3 , 1 , 1 ), B)
470
- @test_throws DimensionMismatch maximum! (fill (0 , 1 , 1 , 2 , 1 ), B)
471
- @test_throws DimensionMismatch minimum! (fill (0 , 1 , 1 , 2 , 1 ), B)
472
502
end
473
503
474
504
# issue #26709
514
544
@testset " type stability (issue #43461)" begin
515
545
@test (@inferred maximum (Float64, reshape (1 : 4 ,2 ,:); dims = 2 )) == reshape ([3 ,4 ],2 ,1 )
516
546
end
547
+
548
+ @testset " Min/Max initialization test" begin
549
+ A = Vector {Union{Missing,Int}} (1 : 4 )
550
+ A[2 ] = missing
551
+ @test @inferred (minimum (exp, A; dims = 1 ))[1 ] === missing
552
+ @test @inferred (maximum (exp, A; dims = 1 ))[1 ] === missing
553
+ @test @inferred (extrema (exp, A; dims = 1 ))[1 ] === (missing , missing )
554
+ end
0 commit comments