From 00437670de09238b5c6ef4d81d1955062b4c93f6 Mon Sep 17 00:00:00 2001 From: Eric Davies Date: Mon, 11 Sep 2017 14:51:52 -0500 Subject: [PATCH] Make searchsorted on ClosedInterval generic over AbstractVector --- src/search.jl | 2 +- test/indexing.jl | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/search.jl b/src/search.jl index dddb403..ae1e1bf 100644 --- a/src/search.jl +++ b/src/search.jl @@ -16,7 +16,7 @@ function searchsortednearest(vec::AbstractVector, x) return idx end # Base only specializes searching ranges by Numbers; so optimize for Intervals -function Base.searchsorted(a::Range, I::ClosedInterval) +function Base.searchsorted(a::AbstractVector, I::ClosedInterval) searchsortedfirst(a, I.left):searchsortedlast(a, I.right) end diff --git a/test/indexing.jl b/test/indexing.jl index 19ae91c..d79a48f 100644 --- a/test/indexing.jl +++ b/test/indexing.jl @@ -108,6 +108,12 @@ A = AxisArray(reshape(1:32, 2, 2, 2, 2, 2), .1:.1:.2, .1:.1:.2, .1:.1:.2, [:a, : @test A[ClosedInterval(.15, .25), ClosedInterval(.05, .15), ClosedInterval(.15, .25), :a] == A.data[2:2, 1:1, 2:2, 1, :] @test A[Axis{:dim_5}(2)] == A.data[:, :, :, :, 2] +# allow SortedVector to force Dimensional behaviour when comparison is possible +A = AxisArray([1,3,2], Axis{:a}(SortedVector(["one", "three", "two"]))) +@test A["three"] == 3 +@test A["three".."three"] == A["thra".."thro"] == AxisArray([3], Axis{:a}(SortedVector(["three"]))) +@test A["a".."z"] == A + # Test vectors v = AxisArray(collect(.1:.1:10.0), .1:.1:10.0) @test v[Colon()] == v