@@ -1874,6 +1874,33 @@ end
1874
1874
end
1875
1875
end
1876
1876
1877
+ @testset " issue 56771, stack(; dims) on containers with HasLength eltype & HasShape elements" begin
1878
+ for T in (Matrix, Array, Any)
1879
+ xs = T[rand (2 ,3 ) for _ in 1 : 4 ]
1880
+ @test size (stack (xs; dims= 1 )) == (4 ,2 ,3 )
1881
+ @test size (stack (xs; dims= 2 )) == (2 ,4 ,3 ) # this was the problem case, for T=Array
1882
+ @test size (stack (xs; dims= 3 )) == (2 ,3 ,4 )
1883
+ @test size (stack (identity, xs; dims= 2 )) == (2 ,4 ,3 )
1884
+ @test size (stack (x for x in xs if true ; dims= 2 )) == (2 ,4 ,3 )
1885
+
1886
+ xmat = T[rand (2 ,3 ) for _ in 1 : 4 , _ in 1 : 5 ]
1887
+ @test size (stack (xmat; dims= 1 )) == (20 ,2 ,3 )
1888
+ @test size (stack (xmat; dims= 2 )) == (2 ,20 ,3 )
1889
+ @test size (stack (xmat; dims= 3 )) == (2 ,3 ,20 )
1890
+ end
1891
+
1892
+ it = Iterators. product (1 : 2 , 3 : 5 )
1893
+ @test size (it) == (2 ,3 )
1894
+ @test Base. IteratorSize (typeof (it)) == Base. HasShape {2} ()
1895
+ @test Base. IteratorSize (Iterators. ProductIterator) == Base. HasLength ()
1896
+ for T in (typeof (it), Iterators. ProductIterator, Any)
1897
+ ys = T[it for _ in 1 : 4 ]
1898
+ @test size (stack (ys; dims= 2 )) == (2 ,4 ,3 )
1899
+ @test size (stack (identity, ys; dims= 2 )) == (2 ,4 ,3 )
1900
+ @test size (stack (y for y in ys if true ; dims= 2 )) == (2 ,4 ,3 )
1901
+ end
1902
+ end
1903
+
1877
1904
@testset " keepat!" begin
1878
1905
a = [1 : 6 ;]
1879
1906
@test a === keepat! (a, 1 : 5 )
0 commit comments