@@ -1705,6 +1705,39 @@ end
17051705 @test istriu ([1 2 0 ; 0 4 1 ])
17061706end
17071707
1708+ # issue 49021
1709+ @testset " reverse cartesian indices" begin
1710+ @test reverse (CartesianIndices ((2 , 3 ))) === CartesianIndices ((2 : - 1 : 1 , 3 : - 1 : 1 ))
1711+ @test reverse (CartesianIndices ((2 : 5 , 3 : 7 ))) === CartesianIndices ((5 : - 1 : 2 , 7 : - 1 : 3 ))
1712+ @test reverse (CartesianIndices ((5 : - 1 : 2 , 7 : - 1 : 3 ))) === CartesianIndices ((2 : 1 : 5 , 3 : 1 : 7 ))
1713+ end
1714+
1715+ @testset " reverse cartesian indices dim" begin
1716+ A = CartesianIndices ((2 , 3 , 5 : - 1 : 1 ))
1717+ @test reverse (A, dims= 1 ) === CartesianIndices ((2 : - 1 : 1 , 3 , 5 : - 1 : 1 ))
1718+ @test reverse (A, dims= 3 ) === CartesianIndices ((2 , 3 , 1 : 1 : 5 ))
1719+ @test_throws ArgumentError reverse (A, dims= 0 )
1720+ @test_throws ArgumentError reverse (A, dims= 4 )
1721+ end
1722+
1723+ @testset " reverse cartesian indices multiple dims" begin
1724+ A = CartesianIndices ((2 , 3 , 5 : - 1 : 1 ))
1725+ @test reverse (A, dims= (1 , 3 )) === CartesianIndices ((2 : - 1 : 1 , 3 , 1 : 1 : 5 ))
1726+ @test reverse (A, dims= (3 , 1 )) === CartesianIndices ((2 : - 1 : 1 , 3 , 1 : 1 : 5 ))
1727+ @test_throws ArgumentError reverse (A, dims= (1 , 2 , 4 ))
1728+ @test_throws ArgumentError reverse (A, dims= (0 , 1 , 2 ))
1729+ @test_throws ArgumentError reverse (A, dims= (1 , 1 ))
1730+ end
1731+
1732+ @testset " stability of const propagation" begin
1733+ A = CartesianIndices ((2 , 3 , 5 : - 1 : 1 ))
1734+ f1 (x) = reverse (x; dims= 1 )
1735+ f2 (x) = reverse (x; dims= (1 , 3 ))
1736+ @test @inferred (f1 (A)) === CartesianIndices ((2 : - 1 : 1 , 3 , 5 : - 1 : 1 ))
1737+ @test @inferred (f2 (A)) === CartesianIndices ((2 : - 1 : 1 , 3 , 1 : 1 : 5 ))
1738+ @test @inferred (reverse (A; dims= ())) === A
1739+ end
1740+
17081741# issue 4228
17091742let A = [[i i; i i] for i= 1 : 2 ]
17101743 @test cumsum (A) == Any[[1 1 ; 1 1 ], [3 3 ; 3 3 ]]
0 commit comments