JuliaIntervals / ValidatedNumerics.jl

Rigorous floating-point calculations with interval arithmetic in Julia
Other
85 stars 17 forks source link

WIP: Mechanism for changing global rounding mode #207

Closed dpsanders closed 7 years ago

dpsanders commented 7 years ago

To use run Julia as follows from the command line:

> VN_ROUNDING=fast julia --compilecache=no

The options are fast, none and correct. The default is correct.

The --compilecache=no is required each time the mode is changed. Currently the VN_ROUNDING=... is required even if the mode is unchanged.

Sample timings for the following benchmark function after warmup:

function bench(N)
    a = 0.1 .. 0.1
    sum(sqrt(n*a) for n in 1:N)
end

julia> bench(10^7)

cc @lbenet

codecov-io commented 7 years ago

Codecov Report

Merging #207 into master will decrease coverage by -2.59%. The diff coverage is 25%.

@@            Coverage Diff             @@
##           master     #207      +/-   ##
==========================================
- Coverage   90.45%   87.86%   -2.59%     
==========================================
  Files          23       23              
  Lines         985     1014      +29     
==========================================
  Hits          891      891              
- Misses         94      123      +29
Impacted Files Coverage Δ
src/ValidatedNumerics.jl 28.57% <ø> (-71.43%) :x:
src/intervals/rounding.jl 34.28% <32.35%> (-40.72%) :x:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 69bd570...8bd37ec. Read the comment docs.

dpsanders commented 7 years ago

As far as I can tell, unfortunately the best / only way to be able to change the global rounding type is in this rather annoying way that cannot be done interactively. The @static if checks things that are known at compile time.

The idea is basically that the rounding mode change is implemented by defining functions like sin(0.5, RoundDown) differently, depending on the global rounding mode, which cannot be changed interactively, or at least not simply and not in 0.6. I am not sure that this is correct or the correct solution, but it seems to work, and allows us to check the effect of using different rounding scenarios.

lbenet commented 7 years ago

I am not sure that this is correct or the correct solution, but it seems to work, and allows us to check the effect of using different rounding scenarios.

The problem I see here is that you are not only changing the behavior of sin(::Interval) but also sin(::Number), which is kind of dangerous.

dpsanders commented 7 years ago

No, I am only changing the behaviour of sin(x::Number, r::RoundingMode). These are functions that are currently only in CRlibm and here.

lbenet commented 7 years ago

Good to hear that the change is only local and affects only CRlibm functions!

What happens if I start Julia as I do always, without the specifications of the environment variable VN_ROUNDING and --compilecahe=no? Do I get the :correct rounding mode, i.e., is that the version that is precompiled?

lbenet commented 7 years ago

Is there a way of including tests with travis?

While I'm not against merging this (as you say, it seems to work), it would be nice to test it more thoroughly.

dpsanders commented 7 years ago

If you start it as you usually do, then you should get the :correct rounding mode, yes.

I do not have any idea how to test this on Travis. I will try to find out.

dpsanders commented 7 years ago

I think I now have a better way of implementing this, so closing.