From 31efb78a597af5bb5d1004a6ff5fc5506e7f689d Mon Sep 17 00:00:00 2001 From: mtsch Date: Tue, 12 May 2020 02:36:18 +0200 Subject: [PATCH 1/4] Add test for get with CartesianIndex --- test/runtests.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index c8e6ac50c..5797c8c65 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -10,6 +10,9 @@ using UUIDs: UUID, uuid1, uuid_version @test length(-ci:ci) == 9 # https://github.com/JuliaLang/julia/pull/29442 @test oneunit(ci) === ci + + @test get([1 2 3; 4 5 6], CartesianIndex(1, 2), 5) == 2 + @test get([1 2 3; 4 5 6], CartesianIndex(10, 2), 5) == 2 end # julia#29679 From 8dcee5842601d1e675bdcc535225b3c8fbb02272 Mon Sep 17 00:00:00 2001 From: mtsch Date: Tue, 12 May 2020 02:38:18 +0200 Subject: [PATCH 2/4] Add `get` for `AbstractArray` and `CartesianIndex`. --- src/Compat.jl | 5 +++++ test/runtests.jl | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Compat.jl b/src/Compat.jl index 760af0eff..5452b4f04 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -17,6 +17,11 @@ if VERSION < v"1.1.0-DEV.403" Base.oneunit(::Type{CartesianIndex{N}}) where {N} = CartesianIndex(ntuple(x -> 1, Val(N))) end +# https://github.com/JuliaLang/julia/pull/30268 +if VERSION < v"1.1.0-DEV.811" + Base.get(A::AbstractArray, I::CartesianIndex, default) = get(A, I.I, default) +end + # https://github.com/JuliaLang/julia/pull/29679 if VERSION < v"1.1.0-DEV.472" export isnothing diff --git a/test/runtests.jl b/test/runtests.jl index 5797c8c65..71caba318 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -10,9 +10,12 @@ using UUIDs: UUID, uuid1, uuid_version @test length(-ci:ci) == 9 # https://github.com/JuliaLang/julia/pull/29442 @test oneunit(ci) === ci - - @test get([1 2 3; 4 5 6], CartesianIndex(1, 2), 5) == 2 - @test get([1 2 3; 4 5 6], CartesianIndex(10, 2), 5) == 2 + # https://github.com/JuliaLang/julia/pull/30268 + A = randn(1,2,3) + @test get(A, CartesianIndex(1,2,3), :some_default) === A[1,2,3] + @test get(A, CartesianIndex(2,2,3), :some_default) === :some_default + @test get(11:15, CartesianIndex(6), nothing) === nothing + @test get(11:15, CartesianIndex(5), nothing) === 15 end # julia#29679 From a29ab83c229e3560422713c74d90c5189e3904d1 Mon Sep 17 00:00:00 2001 From: mtsch Date: Wed, 13 May 2020 02:11:53 +0200 Subject: [PATCH 3/4] update README --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 6b4bd4206..6a044af89 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,8 @@ Please check the list below for the specific syntax you need. ## Supported features +* `get` supporting `CartesianIndex` when indexing `AbstractArrays` ([#30259]). + * `similar(::PermutedDimsArray)` now uses the parent ([#35304]). (since Compat 3.9.0) * `isdisjoint(l, r)` indicates whether two collections are disjoint ([#34427]). (since Compat 3.9.0) @@ -148,3 +150,4 @@ Note that you should specify the correct minimum version for `Compat` in the [#34652]: https://github.com/JuliaLang/julia/issues/34652 [#34773]: https://github.com/JuliaLang/julia/issues/34773 [#35304]: https://github.com/JuliaLang/julia/pull/35304 +[#30259]: https://github.com/JuliaLang/julia/pull/30268 From 7fb63a63ac34ba4adf142e78cb782bbb43820ea2 Mon Sep 17 00:00:00 2001 From: mtsch Date: Fri, 15 May 2020 01:59:08 +0200 Subject: [PATCH 4/4] bump version, update README --- Project.toml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 7b07692ee..a5a32dbef 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "Compat" uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" -version = "3.9.1" +version = "3.10.0" [deps] Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" diff --git a/README.md b/README.md index 6a044af89..f9965bae0 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Please check the list below for the specific syntax you need. ## Supported features -* `get` supporting `CartesianIndex` when indexing `AbstractArrays` ([#30259]). +* `get` supports `CartesianIndex` when indexing `AbstractArrays` ([#30259]). (since Compat 3.10.0) * `similar(::PermutedDimsArray)` now uses the parent ([#35304]). (since Compat 3.9.0)