Skip to content

Commit b4f7e5e

Browse files
authored
Merge pull request #706 from mateuszbaran/mbaran/zero-dim-view
Views of zero-dimensional arrays
2 parents 103e9d4 + c060f73 commit b4f7e5e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/indexing.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,4 +378,6 @@ Base.unsafe_view(A::AbstractArray, i1::StaticIndexing, indices::StaticIndexing..
378378
# Additionally, in some cases the SubArray constructor may be called directly
379379
# instead of unsafe_view so we need this method too (Base._maybe_reindex
380380
# is a good example)
381-
Base.SubArray(A::AbstractArray, indices::NTuple{<:Any,StaticIndexing}) = Base.SubArray(A, map(unwrap, indices))
381+
# the tuple indices has to have at least one element to prevent infinite
382+
# recursion when viewing a zero-dimensional array (see issue #705)
383+
Base.SubArray(A::AbstractArray, indices::Tuple{StaticIndexing, Vararg{StaticIndexing}}) = Base.SubArray(A, map(unwrap, indices))

test/indexing.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,14 @@ using StaticArrays, Test
205205
@test (zeros(2,0)[SVector(1),SVector{0,Int}()] = 0) == 0
206206
end
207207

208+
@testset "Viewing zero-dimensional arrays" begin
209+
# issue #705
210+
A = zeros()
211+
B = MArray{Tuple{},Float64,0,1}(0.0)
212+
@test @inferred(view(A))[] == 0.0
213+
@test @inferred(view(B))[] == 0.0
214+
end
215+
208216
@testset "Using SArray as index for view" begin
209217
a = collect(11:20)
210218
@test view(a, SVector(1,2,3)) == [11,12,13]

0 commit comments

Comments
 (0)