-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should eltype(1..2) be Float64? (currently it is Int) #115
Comments
This has caused confusion in JuliaReinforcementLearning/CommonRLSpaces.jl#12. |
Why julia> big(π) in 0..4
true I think |
I'm not sure we need The most consistent way would be rename |
I once had a crazy idea of implementing So I think removing |
I think the ship has sailed, up to some details. The choice in this package is that an interval is defined by the membership function Personally, I'm also happy with having julia> A = [1,2,3]
3-element Vector{Int64}:
1
2
3
julia> eltype(A)
Int64
julia> 2.0 ∈ A
true What Of course it is annoying that In DomainSets the |
Perhaps we could have |
We currently support julia> using Dates, IntervalSets
julia> Date(2022,08,12) .. Date(2022,09,12)
2022-08-12..2022-09-12
julia> Date(2022,09,10) in ans
true |
One possible rule would be: if the bounds are |
How about |
Thanks, that's a cool example. |
I think this is the core issue. |
I somewhat agree, but there is a dual issue to this one in which people discuss why |
Agreed. How about if the bounds are |
For some perspective, in
That is more or less what happens here, as the inequality |
What about |
We still have counterexamples
Or |
Those are not |
I don't think that, as a user of |
On second thought, something like |
Note replacing julia> b = typemax(Int); a = b-1;
julia> a..b
9223372036854775806..9223372036854775807
julia> float(a)..float(b)
9.223372036854776e18..9.223372036854776e18
julia> a in (float(a)..float(b))
false ApproxFun has something called To me the |
I think it would make a lot of sense to introduce |
In what practical situations is the interval "eltype" used?
This example is just around tests, and it can be replaced with @test eltype(tp) <: Tuple{Real, Real} |
Whenever an algorithm needs to deal with elements of some set but is only provided with the set itself, i.e. function f(set)
d = Dict{eltype(set), Float64}()
# fill up d
end A concrete example is in reinforcement learning, a user might specify the action space as It is true that most of the time you can avoid needing |
Oh shoot, I misinterpreted the comment above, so it wouldn't necessarily be |
This is a fair point. However, through promotion, the package currently does similar conversions anyway: julia> (1..2) ∪ (1.5..2.5)
1.0..2.5 And Base does it too for ranges between integers, if it is clear that elements will be reals: julia> range(0, 1, length=100)
0.0:0.010101010101010102:1.0
julia> typeof(ans)
StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64} |
As @dlfivefifty also mentioned, one important goal is to convey the expected numerical accuracy (which leads to To answer the original question of how this issue affects DomainSets: I think it doesn't. We just define I think a counter question might be in which kind of situations it matters that |
But in my example above |
Well, if you construct a set like that, maybe you deserve to get only one element 😜 ! Just kidding. |
I know you are just kidding (and so am I!) but it is important to be consistent: arbitrarily converting to floats will just add unnecessary confusion because at some point someone will want an interval containing large ints. I'm wondering if you would be better off just calling |
It's not really an arbitrary conversion though. Nobody argues for disallowing Interval{T} with integer T. Instead there is a question of how easy that should be (and in particular whether it should be the default).
In the second scenario there would be a visual clue that something happened to inform the user: julia> 1..2
1.0..2.0 This is comparable to: julia> 1:0.01:2
1.0:0.01:2.0 You don't want to have the endpoints of a range have a different type from the elements of the range. Since this package aims to be a "minimal foundation", the first option may make more sense. In that case I would define eltype in DomainSets. On the other hand, quoting from the first line of the readme: "This package represents intervals of an ordered set." In Julia I'd expect any kind of set to implement Finally, it makes little sense for (Sidenote, if it stays, perhaps |
After working on JuliaApproximation/DomainSets.jl#112, here are my thoughts:
Thus I think I agree with @daanhb 's second suggestion above. |
Btw, Intervals.jl has the same julia> using Intervals
julia> 1..2
Interval{Int64, Closed, Closed}(1, 2)
julia> eltype(1..2)
Int64
julia> eltype(1..2.)
Float64 |
It seems quite strange to me that
eltype(1..2)
isInt
because the elements in the mathematical set [1,2] are real numbers, and real numbers are usually represented byFloat64
.Happy to make a PR if people support this.
The text was updated successfully, but these errors were encountered: