Skip to content

Commit 6d09a18

Browse files
committed
Fix indexing empty arrays
1 parent 355e0c0 commit 6d09a18

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/indexing.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ end
229229
# Iterate over input indices
230230
ind_types = inds.parameters
231231
current_ind = ones(Int,length(linearsizes))
232-
more = linearsizes[1] != 0
232+
more = !isempty(exprs)
233233
while more
234234
exprs_tmp = [_ind(i, current_ind[i], ind_types[i]) for i = 1:length(linearsizes)]
235235
exprs[current_ind...] = :(getindex(a, $(exprs_tmp...)))
@@ -331,7 +331,7 @@ end
331331
# Iterate over input indices
332332
ind_types = inds.parameters
333333
current_ind = ones(Int,length(ind_types))
334-
more = linearsizes[1] != 0
334+
more = !isempty(exprs)
335335
while more
336336
exprs_tmp = [_ind(i, current_ind[i], ind_types[i]) for i = 1:length(ind_types)]
337337
exprs[current_ind...] = :(setindex!(a, value, $(exprs_tmp...)))

test/indexing.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,19 @@
153153
@test b == a
154154
end
155155

156+
@testset "Indexing empty arrays" begin
157+
@test size(SVector{0}()[:]) == (0,)
158+
@test size(SMatrix{0,0}()[:,:]) == (0,0)
159+
@test size(SMatrix{5,0}()[1,:]) == (0,)
160+
@test size(SMatrix{5,0}()[:,:]) == (5,0)
161+
@test size(SMatrix{0,5}()[:,1]) == (0,)
162+
@test size(SMatrix{0,5}()[:,:]) == (0,5)
163+
164+
@test (zeros(0)[SVector{0,Int}()] = 0) == 0
165+
@test (zeros(0,2)[SVector{0,Int}(),SVector(1)] = 0) == 0
166+
@test (zeros(2,0)[SVector(1),SVector{0,Int}()] = 0) == 0
167+
end
168+
156169
@testset "inferabilty of index_sizes helper" begin
157170
# see JuliaLang/julia#21244
158171
# it's not about inferring the correct type, but about inference throwing an error

0 commit comments

Comments
 (0)