Skip to content

Commit af70b76

Browse files
committed
Make innersize() type-stable with workaround for Julia issue #15276
1 parent 228f048 commit af70b76

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/functions.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,19 @@ export innersize
8888

8989
function innersize(A::AbstractArray{<:AbstractArray{T,M},N}) where {T,M,N}
9090
s = if !isempty(A)
91-
sz_A = size(first(A))
92-
ntuple(i -> Int(sz_A[i]), Val(M))
91+
let sz_A = size(first(A))
92+
ntuple(i -> Int(sz_A[i]), Val(M))
93+
end
9394
else
9495
ntuple(_ -> zero(Int), Val(M))
9596
end
9697

97-
all(X -> size(X) == s, A) || throw(DimensionMismatch("Shape of element arrays of A is not equal, can't determine common shape"))
98+
let s = s
99+
if any(X -> size(X) != s, A)
100+
throw(DimensionMismatch("Shape of element arrays of A is not equal, can't determine common shape"))
101+
end
102+
end
103+
98104
s
99105
end
100106

test/functions.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ using StaticArrays
2525
end
2626

2727

28+
@testset "innersize" begin
29+
@test @inferred(innersize([[1, 2, 3], [4, 5, 6]])) == (3,)
30+
@test @inferred(innersize([[]])) == (0,)
31+
@test_throws DimensionMismatch @inferred(innersize([[1, 2, 3], [4, 5]]))
32+
end
33+
34+
2835
@testset "deepgetindex" begin
2936
A = gen_nested()
3037
@test @inferred(deepgetindex(A, 1, 2)) === A[1, 2]

0 commit comments

Comments
 (0)