From 48fcacfc21b194aff97863a8776f3eff7dc84457 Mon Sep 17 00:00:00 2001 From: Matt Bauman Date: Sat, 28 Feb 2015 12:47:11 -0500 Subject: [PATCH] Add missing subarray method and test --- base/subarray2.jl | 2 +- test/subarray.jl | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/base/subarray2.jl b/base/subarray2.jl index 7d618dcc62828..7a996a04d5e15 100644 --- a/base/subarray2.jl +++ b/base/subarray2.jl @@ -83,7 +83,7 @@ end # is just a matter of deleting the explicit call to copy. getindex{T,N,P,IV}(V::SubArray{T,N,P,IV}, I::ViewIndex...) = copy(sub(V, I...)) getindex{T,N,P,IV}(V::SubArray{T,N,P,IV}, I::AbstractArray{Bool,N}) = copy(sub(V, find(I))) # this could be much better optimized -getindex{T,N,P,IV}(V::SubArray{T,N,P,IV}, I::Union(Real, AbstractVector)...) = getindex(V, to_index(I)...) +getindex{T,N,P,IV}(V::SubArray{T,N,P,IV}, I::Union(Real, AbstractVector, Colon)...) = getindex(V, to_index(I)...) function setindex!{T,P,IV}(V::SubArray{T,1,P,IV}, v, I::AbstractArray{Bool,1}) length(I) == length(V) || throw(DimensionMismatch("logical vector must match array length")) diff --git a/test/subarray.jl b/test/subarray.jl index b3780b95afa75..723fc66b823e5 100644 --- a/test/subarray.jl +++ b/test/subarray.jl @@ -331,6 +331,8 @@ sA = sub(A, 1:2:3, 1:3:5, 1:2:8) @test sA[:] == A[1:2:3, 1:3:5, 1:2:8][:] # issue #8807 @test sub(sub([1:5;], 1:5), 1:5) == [1:5;] +# Test with mixed types +@test sA[:, Int16[1,2], 2.0] == [31 40; 33 42] # sub logical indexing #4763 A = sub([1:10;], 5:8)