From a33080d17e611dd028e50ee716e8c7af4da2e95e Mon Sep 17 00:00:00 2001 From: Felix Eckhofer Date: Fri, 18 Jan 2019 09:58:23 +0100 Subject: [PATCH] Allow using static arrays as index for views --- src/indexing.jl | 8 ++++++++ test/indexing.jl | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/src/indexing.jl b/src/indexing.jl index 21edb874..ffa05ff5 100644 --- a/src/indexing.jl +++ b/src/indexing.jl @@ -346,3 +346,11 @@ end end end end + +# checkindex + +Base.checkindex(B::Type{Bool}, inds::AbstractUnitRange, i::StaticIndexing{T}) where T = Base.checkindex(B, inds, unwrap(i)) + +# unsafe_view + +Base.unsafe_view(A::AbstractArray, i::StaticIndexing{T}) where T = Base.unsafe_view(A, unwrap(i)) diff --git a/test/indexing.jl b/test/indexing.jl index b35c8c9e..a664757b 100644 --- a/test/indexing.jl +++ b/test/indexing.jl @@ -181,4 +181,10 @@ using StaticArrays, Test @test (zeros(0,2)[SVector{0,Int}(),SVector(1)] = 0) == 0 @test (zeros(2,0)[SVector(1),SVector{0,Int}()] = 0) == 0 end + + @testset "Using SArray as index for view" begin + a = collect(11:20) + @test view(a, SVector(1,2,3)) == [11,12,13] + @test_throws BoundsError view(a, SVector(1,11,3)) + end end