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

Make Interval constructor fast by not including checks #26

Merged
merged 23 commits into from
Jun 25, 2017

Conversation

dpsanders
Copy link
Member

@dpsanders dpsanders commented May 1, 2017

The IA_VALID environment variable now determines if validity checks are used. E.g. run Julia with

IA_VALID=true julia --compilecache=no

to turn on validity checks; by default, they are off.

@codecov-io
Copy link

codecov-io commented May 2, 2017

Codecov Report

Merging #26 into master will decrease coverage by 0.41%.
The diff coverage is 81.48%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #26      +/-   ##
==========================================
- Coverage   91.64%   91.22%   -0.42%     
==========================================
  Files          21       21              
  Lines         969      980      +11     
==========================================
+ Hits          888      894       +6     
- Misses         81       86       +5
Impacted Files Coverage Δ
src/IntervalArithmetic.jl 100% <ø> (ø) ⬆️
src/multidim/intervalbox.jl 87.5% <ø> (ø) ⬆️
src/intervals/macros.jl 100% <100%> (ø) ⬆️
src/intervals/arithmetic.jl 97.51% <100%> (-0.02%) ⬇️
src/intervals/intervals.jl 86.48% <79.16%> (-13.52%) ⬇️

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 e17aeef...42124cc. Read the comment docs.

@coveralls
Copy link

coveralls commented May 28, 2017

Coverage Status

Coverage decreased (-1.08%) to 91.323% when pulling 2dd3a2e on simplify_constructor into 0d7f112 on master.

@coveralls
Copy link

coveralls commented May 28, 2017

Coverage Status

Coverage decreased (-1.08%) to 91.323% when pulling 2dd3a2e on simplify_constructor into 0d7f112 on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-3.7%) to 87.891% when pulling 8952216 on simplify_constructor into 2ecefe5 on master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-3.7%) to 87.891% when pulling 8952216 on simplify_constructor into 2ecefe5 on master.

@lbenet
Copy link
Member

lbenet commented Jun 11, 2017

What should we do about this? This is already included through the :accurate rounding mode.

Copy link
Member

@lbenet lbenet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very nice, thank you.

However, I dislike when the default behavior goes away from compliance with the standard. My main suggestion is to have the defaults to be closest to the standard, and only by explicit choice by the user, get away from that default behavior.

@@ -5,37 +5,34 @@

## Interval type

const validity_check = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the default value should be true, since that is the case that (eventually) will ensure compliance with the standard. This could be changed by the IA_VALID environment variable, which I guess can be set also in the .juliarc file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another reason to change this default is the fact that many users may construct directly the intervals using the constructor instead of interval...

end

interval(a::Real) = interval(a, a)

Copy link
Member

@lbenet lbenet Jun 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand interval always checks the validity of the construction, while
Interval does not (currently as defualt) unless IA_VALID=true. Is this correct?

Yes, exactly: the user is supposed to use the interval function to build an Interval, rather than the Interval constructor itself. Since the interval function does perform checks, I don't think there is any problem with standards compliance.

In fact, my idea would be that the Interval constructor should not even be exported, so that it cannot be used "accidentally".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add some docstrings here?

@test_throws ArgumentError interval(big(2), big(1))
@test_throws ArgumentError interval(BigInt(1), 1//10)
@test_throws ArgumentError interval(1, 0.1)
@test_throws ArgumentError interval(big(1), big(0.1))

Copy link
Member

@lbenet lbenet Jun 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If my comment about interval is correct (interval checks the validity and Interval may not), I think it is a good idea to test the differences among Interval and interval when their behavior differs.

EDIT: Fix the 's

# a = interval(Inf, NaN)
# @test isnan(a.lo) && isnan(a.hi)
#
# end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these tests disallowed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, I think they should be added back, thanks.

for op in (exp, log, sin, tan)
@bench string(op) $(op)($a)
end
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this erased?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebase problem, sorry.

else
const validity_check = false
end

abstract type AbstractInterval{T} <: Real end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This was not there when I began reviewing.)
My suggestion (see elsewhere) is that the default is to have the validity being checked.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 91.513% when pulling 07fbd81 on simplify_constructor into f4be4b6 on master.

1 similar comment
@coveralls
Copy link

coveralls commented Jun 22, 2017

Coverage Status

Coverage decreased (-0.1%) to 91.513% when pulling 07fbd81 on simplify_constructor into f4be4b6 on master.

@coveralls
Copy link

coveralls commented Jun 24, 2017

Coverage Status

Coverage decreased (-0.1%) to 91.522% when pulling 539e047 on simplify_constructor into f4be4b6 on master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 91.522% when pulling 539e047 on simplify_constructor into f4be4b6 on master.

@lbenet
Copy link
Member

lbenet commented Jun 24, 2017

I think that docstrings are still missing.

I still do not understand the need for the ENV variable.

While we agree to not export Interval, why not AbstractInterval? I thought the idea of having AbstractInterval was to allow other (external?) types use the same functionality. I know it is not yet implemented that way, so currently I agree to not export it; I just want to write this somewhere to be aware of it.

@dpsanders
Copy link
Member Author

The ENV variable is the only method I have found to turn on and off the validity checks, such that the code is compiled with no validity checks if validity_check is false.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.0008%) to 91.633% when pulling 5c3012a on simplify_constructor into f4be4b6 on master.

1 similar comment
@coveralls
Copy link

coveralls commented Jun 24, 2017

Coverage Status

Coverage increased (+0.0008%) to 91.633% when pulling 5c3012a on simplify_constructor into f4be4b6 on master.

@coveralls
Copy link

coveralls commented Jun 24, 2017

Coverage Status

Coverage decreased (-0.5%) to 91.131% when pulling d4628a8 on simplify_constructor into e17aeef on master.

@coveralls
Copy link

coveralls commented Jun 24, 2017

Coverage Status

Coverage decreased (-0.5%) to 91.131% when pulling d4628a8 on simplify_constructor into e17aeef on master.

@coveralls
Copy link

coveralls commented Jun 24, 2017

Coverage Status

Coverage decreased (-0.5%) to 91.131% when pulling d4628a8 on simplify_constructor into e17aeef on master.

1 similar comment
@coveralls
Copy link

coveralls commented Jun 24, 2017

Coverage Status

Coverage decreased (-0.5%) to 91.131% when pulling d4628a8 on simplify_constructor into e17aeef on master.

@dpsanders
Copy link
Member Author

@lbenet It would be great if you could have another final look over this. I think I have addressed all the comments and I'm pretty happy with how it's looking.

@coveralls
Copy link

coveralls commented Jun 24, 2017

Coverage Status

Coverage decreased (-0.4%) to 91.224% when pulling 42124cc on simplify_constructor into e17aeef on master.

@lbenet
Copy link
Member

lbenet commented Jun 25, 2017

I've checked and everything seems consistent and nice. I'm actually ready to merge, but I'd like to add the following suggestions:

  1. Merging this PR implies that we will have as the default behavior (no IA_VALID ENV variable, or IA_VALID being whatever except "true") that validity_check is false. The user a priori has to use interval, which always checks the validity of the construction of the interval (complying with the standard); that's really nice. Then, why should there be a key IA_VALID at all? My suggestion is to get rid completely of it and also of validity_check.

  2. Following with the previous point, we can also get rid of the current inner constructor (since there is no validity_check), and change the current outer constructors to be methods of interval. In that way, if the user really wants to use the Interval constructor, it will have to be called as IntervalArithmetic.Interval{T}(a,b), with the appropriate T, which is nasty enough to be done frequently.

What do you think about this?

@lbenet
Copy link
Member

lbenet commented Jun 25, 2017

A priori, I am in favor of merging this, and also incorporate my two suggestions above.

@lbenet
Copy link
Member

lbenet commented Jun 25, 2017

Or should the above suggestions be submitted as a different PR?

@dpsanders
Copy link
Member Author

I think it makes sense to have the possibility of using validity_check with every construction of an Interval, in case any more bugs in our library code are found.

It's not actually clear to me if unexporting Interval is a good idea, since that currently makes using downstream packages (IntervalRootFinding) more difficult; but probably we just need to update those in the right way.

@lbenet
Copy link
Member

lbenet commented Jun 25, 2017

Merging, then.

Regarding your comments, if validity_check is true, then we are passing through is_valid_interval twice. I agree that we should update the rest of the packages so interval is used.

@lbenet lbenet merged commit 00bbdce into master Jun 25, 2017
@dpsanders dpsanders deleted the simplify_constructor branch August 2, 2017 19:39
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

Successfully merging this pull request may close these issues.

4 participants