From 76cae0a564fff2a0438d712f058e6380411a42ce Mon Sep 17 00:00:00 2001 From: Hendrik Ranocha Date: Fri, 20 Oct 2017 16:43:14 +0200 Subject: [PATCH] getindex(A::AbstractArray, ::Val{:..}) --- src/EllipsisNotation.jl | 4 ++++ test/basic.jl | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/EllipsisNotation.jl b/src/EllipsisNotation.jl index 8cec96d..4269e1f 100644 --- a/src/EllipsisNotation.jl +++ b/src/EllipsisNotation.jl @@ -18,6 +18,10 @@ const .. = Val{:..}() to_indices(A, inds, (colons..., tail(I)...)) end +# avoid copying if indexing with .. alone, see +# https://github.com/JuliaDiffEq/OrdinaryDiffEq.jl/issues/214 +@inline Base.getindex(A::AbstractArray, ::Val{:..}) = A + export .. end # module diff --git a/test/basic.jl b/test/basic.jl index 9783582..913697e 100644 --- a/test/basic.jl +++ b/test/basic.jl @@ -24,4 +24,17 @@ B = [3 4 @test B == reshape(A[1,..],4,2) == reshape(view(A, 1,..), 4, 2) -@test A[:,1,2] == A[..,1,2] == @view A[..,1,2] \ No newline at end of file +@test A[:,1,2] == A[..,1,2] == @view A[..,1,2] + +# [..] +C = zeros(B) + +C[:] = B[..] +@test B == C +C[1,1] += 1 +@test B != C + +C[..] = B[..] +@test B == C +C[1,1] += 1 +@test B != C