Skip to content

Commit e78e550

Browse files
committed
fix 56771
1 parent c940a31 commit e78e550

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

base/abstractarray.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2915,8 +2915,6 @@ _iterator_axes(x, ::IteratorSize) = axes(x)
29152915
# For some dims values, stack(A; dims) == stack(vec(A)), and the : path will be faster
29162916
_typed_stack(dims::Integer, ::Type{T}, ::Type{S}, A) where {T,S} =
29172917
_typed_stack(dims, T, S, IteratorSize(S), A)
2918-
_typed_stack(dims::Integer, ::Type{T}, ::Type{S}, ::HasLength, A) where {T,S} =
2919-
_typed_stack(dims, T, S, HasShape{1}(), A)
29202918
function _typed_stack(dims::Integer, ::Type{T}, ::Type{S}, ::HasShape{N}, A) where {T,S,N}
29212919
if dims == N+1
29222920
_typed_stack(:, T, S, A, (_vec_axis(A),))

test/abstractarray.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,6 +1874,33 @@ end
18741874
end
18751875
end
18761876

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+
18771904
@testset "keepat!" begin
18781905
a = [1:6;]
18791906
@test a === keepat!(a, 1:5)

0 commit comments

Comments
 (0)