Skip to content

Commit

Permalink
Add missing subarray method and test
Browse files Browse the repository at this point in the history
  • Loading branch information
mbauman committed Mar 6, 2015
1 parent f31cb0f commit 48fcacf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/subarray2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
2 changes: 2 additions & 0 deletions test/subarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 48fcacf

Please sign in to comment.