Skip to content

Commit

Permalink
handle stack with abstract eltype
Browse files Browse the repository at this point in the history
  • Loading branch information
adienes committed Dec 7, 2024
1 parent 3a68b03 commit 8caba70
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2962,6 +2962,12 @@ _typed_stack(dims::Integer, ::Type{T}, ::Type{S}, A) where {T,S} =
_typed_stack(dims, T, S, IteratorSize(S), A)
_typed_stack(dims::Integer, ::Type{T}, ::Type{S}, ::HasLength, A) where {T,S} =
_typed_stack(dims, T, S, HasShape{1}(), A)

function _typed_stack(dims::Integer, ::Type{T}, ::Type{S}, ::HasLength, A) where {T,S<:AbstractArray}
N = ndims(first(A))
_typed_stack(dims, T, S, HasShape{N}(), A)
end

function _typed_stack(dims::Integer, ::Type{T}, ::Type{S}, ::HasShape{N}, A) where {T,S,N}
if dims == N+1
_typed_stack(:, T, S, A, (_vec_axis(A),))
Expand Down
3 changes: 3 additions & 0 deletions test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1834,6 +1834,9 @@ end
@test_throws ArgumentError stack(())
@test_throws ArgumentError stack([])
@test_throws ArgumentError stack(x for x in 1:3 if false)

# issue #56771
@test size(stack(AbstractArray[ones(1,2) for _=1:3]; dims=2)) == (1, 3, 2)
end

@testset "tests from PR 31644" begin
Expand Down

0 comments on commit 8caba70

Please sign in to comment.