Skip to content

Commit dd3de80

Browse files
authored
Fix float block index causing hang due to infinite recursion (#492)
Calling `BlockIndex((1.0, 2.0), (1,2))` currently causes an infinite growth of the tuple `b`, which this PR fixes by requiring tuple `a` to have integer elements. This lead to the computer just working for a very long time (at least 10 minutes) without any error message.
1 parent a1f2273 commit dd3de80

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/blockindices.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ end
172172
@inline BlockIndex(::Tuple{}, b::Tuple{}) = BlockIndex{0,Tuple{},Tuple{}}((), ())
173173

174174
@inline BlockIndex(a::Integer, b) = BlockIndex((a,), (b,))
175-
@inline BlockIndex(a::Tuple, b) = BlockIndex(a, (b,))
175+
@inline BlockIndex(a::NTuple{N, Integer}, b) where {N} = BlockIndex(a, (b,))
176176
@inline BlockIndex(a::Integer, b::Tuple) = BlockIndex((a,), b)
177177
@inline BlockIndex() = BlockIndex((), ())
178178

test/test_blockindices.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ import BlockArrays: split_index, merge_indices
113113
@test copy(Block(1)[1:2]) === BlockIndexRange(Block(1),1:2)
114114
@test copy(Block(1)[[1,3]]) == BlockIndices(Block(1),[1,3])
115115
@test copy(Block(1)[[1,3]]) BlockIndices(Block(1),[1,3])
116+
@test_throws MethodError BlockIndex((1.0, 2.0), (1, 2))
116117
end
117118

118119
@testset "BlockIndices" begin

0 commit comments

Comments
 (0)