From 52c6ed7ad2723a9eb295eeca4d59d37b6b57fbd7 Mon Sep 17 00:00:00 2001 From: Martin Holters Date: Tue, 8 Oct 2019 18:27:55 +0200 Subject: [PATCH] Drop compat code for `selectdim` from #522 and #531 --- README.md | 2 -- src/Compat.jl | 11 ----------- test/old.jl | 14 ++++++++++++++ test/runtests.jl | 17 ----------------- 4 files changed, 14 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 8bf9aff78..4d2a0cc5f 100644 --- a/README.md +++ b/README.md @@ -72,8 +72,6 @@ Currently, the `@compat` macro supports the following syntaxes: * `range` supporting `stop` as positional argument ([#28708]). -* `selectdim` to obtain a view of an array with a specified index for a specified dimension ([#26009]). - * Single-argument `permutedims(x)` for matrices and vectors ([#24839]). * `fetch` for `Task`s ([#25940]). diff --git a/src/Compat.jl b/src/Compat.jl index 1342de441..453ad5418 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -76,17 +76,6 @@ end end end -if !isdefined(Base, :selectdim) # 0.7.0-DEV.3976 - export selectdim - @inline selectdim(A::AbstractArray, d::Integer, i) = _selectdim(A, d, i, Base.setindex(map(Base.Slice, axes(A)), i, d)) - @noinline function _selectdim(A, d, i, idxs) - d >= 1 || throw(ArgumentError("dimension must be ≥ 1")) - nd = ndims(A) - d > nd && (i == 1 || throw(BoundsError(A, (ntuple(k->Colon(),d-1)..., i)))) - return view(A, idxs...) - end -end - if VERSION < v"0.7.0-DEV.3977" #26039 Base.repeat(A::AbstractArray, counts::Integer...) = Base.repeat(A, outer = counts) Base.repeat(a::AbstractVecOrMat, m::Integer, n::Integer=1) = Base.repmat(a, m, n) diff --git a/test/old.jl b/test/old.jl index 8c4d1ec1b..bb9adc41e 100644 --- a/test/old.jl +++ b/test/old.jl @@ -1026,3 +1026,17 @@ end if VERSION < v"0.7.0-DEV.5165" @test_throws UndefKeywordError Compat.cat([1, 2], [3, 4]) end + +# 0.7.0-DEV.3976 +let A = rand(5,5) + @test selectdim(A, 1, 3) == A[3, :] + @test selectdim(A, 1, 1:3) == A[1:3, :] + @test selectdim(A, 2, 3) == A[:, 3] + @test selectdim(A, 2, 1:3) == A[:, 1:3] + selectdim(A, 1, 3)[3] = 42 + @test A[3,3] == 42 + B = rand(4, 3, 2) + @test IndexStyle(selectdim(B, 1, 1)) == IndexStyle(view(B, 1, :, :)) == IndexLinear() + @test IndexStyle(selectdim(B, 2, 1)) == IndexStyle(view(B, :, 1, :)) == IndexCartesian() + @test IndexStyle(selectdim(B, 3, 1)) == IndexStyle(view(B, :, :, 1)) == IndexLinear() +end diff --git a/test/runtests.jl b/test/runtests.jl index 4ea6513b1..05e6576d2 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -87,23 +87,6 @@ end @test length(Compat.CartesianIndices((1:2,))) == 2 @test length(Compat.CartesianIndices((1:2, -1:1))) == 6 -# 0.7.0-DEV.3976 -let A = rand(5,5) - @test selectdim(A, 1, 3) == A[3, :] - @test selectdim(A, 1, 1:3) == A[1:3, :] - @test selectdim(A, 2, 3) == A[:, 3] - @test selectdim(A, 2, 1:3) == A[:, 1:3] - selectdim(A, 1, 3)[3] = 42 - @test A[3,3] == 42 - if VERSION < v"0.7.0-DEV.3976" || VERSION >= v"0.7.0-DEV.4739" - # in the omitted version range, Julia's selectdim always gives IndexCartesian() - B = rand(4, 3, 2) - @test IndexStyle(selectdim(B, 1, 1)) == IndexStyle(view(B, 1, :, :)) == IndexLinear() - @test IndexStyle(selectdim(B, 2, 1)) == IndexStyle(view(B, :, 1, :)) == IndexCartesian() - @test IndexStyle(selectdim(B, 3, 1)) == IndexStyle(view(B, :, :, 1)) == IndexLinear() - end -end - # 0.7.0-DEV.843 / 0.7.0-DEV.2337 let A = [1 2; 1 2; 1 2] if VERSION < v"0.7.0-DEV.5211"