Skip to content

Commit

Permalink
Merge pull request #145 from rafaqz/noatol
Browse files Browse the repository at this point in the history
Remove auto atol for At
  • Loading branch information
rafaqz authored Aug 18, 2020
2 parents 0476efc + 1556762 commit 72bfbf9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
18 changes: 7 additions & 11 deletions src/selector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ struct At{T,A,R} <: Selector{T}
atol::A
rtol::R
end
At(val::Union{Number,AbstractArray{<:Number},Tuple{<:Number,Vararg}};
atol=zero(eltype(val)),
rtol=(atol > zero(eltype(val)) ? zero(rtol) : Base.rtoldefault(eltype(val)))
) = At{typeof.((val, atol, rtol))...}(val, atol, rtol)
At(val; atol=nothing, rtol=nothing) =
At{typeof.((val, atol, rtol))...}(val, atol, rtol)

Expand Down Expand Up @@ -270,13 +266,13 @@ end
i == nothing && selvalnotfound(dim, selval)
return i
end
@inline at(dim::Dimension, selval, atol, rtol) = begin
# This is not particularly efficient. It should be separated
# out for unordered dims and otherwise treated as an ordered list.
i = findfirst(x -> isapprox(x, selval; atol=atol, rtol=rtol), val(dim))
i == nothing && selvalnotfound(dim, selval)
return i
end
# @inline at(dim::Dimension, selval, atol, rtol) = begin
# # This is not particularly efficient. It should be separated
# # out for unordered dims and otherwise treated as an ordered list.
# i = findfirst(x -> isapprox(x, selval; atol=atol, rtol=rtol), val(dim))
# i == nothing && selvalnotfound(dim, selval)
# return i
# end

@noinline selvalnotfound(dim, selval) =
throw(ArgumentError("$selval not found in $dim"))
Expand Down
14 changes: 6 additions & 8 deletions test/selector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,9 @@ end
da = DimensionalArray(a, (Y((10, 30); mode=Sampled()),
Ti((1:4)u"s"; mode=Sampled())))

@test At(10.0) == At(10.0, 0.0, Base.rtoldefault(eltype(10.0)))
x = [10.0, 20.0]
@test At(x) === At(x, 0.0, Base.rtoldefault(eltype(10.0)))
@test At((10.0, 20.0)) === At((10.0, 20.0), 0.0, Base.rtoldefault(eltype(10.0)))

@test At(10.0) == At(10.0, nothing, nothing)
@test At(10.0; atol=0.0, rtol=Base.rtoldefault(Float64)) ==
At(10.0, 0.0, Base.rtoldefault(Float64))
Near([10, 20])

@test Between(10, 20) == Between((10, 20))
Expand Down Expand Up @@ -530,11 +528,11 @@ end
5 6 7 8
9 10 11 12]

valdimz = Ti(Val((:one, :two, :three)); mode=Categorical(Ordered())),
valdimz = Ti(Val((2.4, 2.5, 2.6)); mode=Categorical(Ordered())),
Y(Val((:a, :b, :c, :d)); mode=Categorical(Ordered()))
da = DimensionalArray(a, valdimz)
@test da[Val(:one), Val(:c)] == 3
@test da[:one, :a] == 1
@test da[Val(2.5), Val(:c)] == 7
@test da[2.4, :a] == 1
end

@testset "Where " begin
Expand Down

0 comments on commit 72bfbf9

Please sign in to comment.