Skip to content
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

Improve Float32 support #415

Closed
dpsanders opened this issue Sep 21, 2020 · 7 comments
Closed

Improve Float32 support #415

dpsanders opened this issue Sep 21, 2020 · 7 comments

Comments

@dpsanders
Copy link
Member

Interval{Float32} support is very patchy, c.f. e.g. #414

Float16 is less useful since arithmetic operations on Float16 just promote to Float32 anyway.

@remi-garcia
Copy link

Couldn't tests be written to enforce a Float32 (and a Float8 and Float16 "just in case") support?
By that I mean rewriting most tests using for loops on types.

using IntervalArithmetic
using Test
@testset "`bisect` function" begin
X = 0..1
@test bisect(X, 0.5) == (0..0.5, 0.5..1)
@test bisect(X, 0.25) == (0..0.25, 0.25..1)
@test bisect(X) == (interval(0.0, 0.49609375), interval(0.49609375, 1.0))
X = -..
@test bisect(X, 0.5) == (-..0, 0..∞)
B = bisect(X, 0.75)
@test B[1].hi > 0
@test B[1].hi == B[2].lo
B = bisect(X, 0.25)
@test B[1].hi < 0
@test B[1].hi == B[2].lo
X = (0..1) × (0..2)
@test bisect(X, 0.5) == ( (0..1) × (0..1), (0..1) × (1..2) )
@test bisect(X, 0.25) == ( (0..1) × (0..0.5), (0..1) × (0.5..2) )
@test bisect(X, 1, 0.5) == ( (0..0.5) × (0..2), (0.5..1) × (0..2) )
@test bisect(X, 1, 0.25) == ( (0..0.25) × (0..2), (0.25..1) × (0..2) )
@test bisect(X) == (IntervalBox(0..1, interval(0.0, 0.9921875)),
IntervalBox(0..1, Interval(0.9921875, 2.0)))
X = (-..∞) × (-..∞)
@test bisect(X, 0.5) == ( (-..0) × (-..∞), (0..∞) × (-..∞))
end

would became

using IntervalArithmetic
using Test


@testset "`bisect` function" begin
    FloatTypes = [Float8, Float16, Float32, Float64]
    for T in FloatTypes
        X = 0..1
        @test bisect(X, T(0.5)) == (T(0)..T(0.5), T(0.5)..T(1))
        @test bisect(X, T(0.25)) == (T(0)..T(0.25), T(0.25)..T(1))

        @test bisect(X) == (interval(T(0.0), T(0.49609375)), interval(T(0.49609375), T(1.0)))

        # [...]
    end
end

@dpsanders
Copy link
Member Author

Yes that's a great idea. (Note that Float8 doesn't exist.)

@remi-garcia
Copy link

remi-garcia commented Apr 16, 2024

With julia 1.6.7

julia> interval(Float16(1))/interval(Float16(0.1))
ERROR: MethodError: no method matching rounding_raw(::Type{Float16})
Closest candidates are:
  rounding_raw(::Type{BigFloat}) at mpfr.jl:121
  rounding_raw(::Type{var"#s77"} where var"#s77"<:Union{Float32, Float64}) at rounding.jl:155
Stacktrace:
 [1] setrounding(f::IntervalArithmetic.var"#29#30"{Float16, Float16}, #unused#::Type{Float16}, rounding::RoundingMode{:Down})
   @ Base.Rounding ./rounding.jl:173
 [2] /(#unused#::IntervalArithmetic.IntervalRounding{:tight}, a::Float16, b::Float16, #unused#::RoundingMode{:Down})
   @ IntervalArithmetic ~/.julia/packages/IntervalArithmetic/EquAX/src/intervals/rounding.jl:177
 [3] /(a::Float16, b::Float16, r::RoundingMode{:Down})
   @ IntervalArithmetic ~/.julia/packages/IntervalArithmetic/EquAX/src/intervals/rounding.jl:278
 [4] /(a::Interval{Float16}, b::Interval{Float16})
   @ IntervalArithmetic ~/.julia/packages/IntervalArithmetic/EquAX/src/intervals/arithmetic.jl:183
 [5] top-level scope
   @ REPL[16]:1

Works with julia 1.10.2

@lbenet
Copy link
Member

lbenet commented Apr 16, 2024

What version of IntervalArithmetic are you using? (I guess it is not v0.22.11, since it restricts to using Julia 1.9 or above)

@remi-garcia
Copy link

  [d1acc4aa] IntervalArithmetic v0.20.9

With julia LTS (1.6.7), this package cannot be updated.

@lbenet
Copy link
Member

lbenet commented Apr 17, 2024

As mentioned, to use more recent versions (which I believe solved the problem reported) you need at least Julia v1.9; I suggest to upgrade to Julia 1.10...

@remi-garcia
Copy link

Yeah, I saw that with julia 1.10.2 and IntervalArithmetic v0.22.11 it works. Just giving some more info on this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants