-
Notifications
You must be signed in to change notification settings - Fork 767
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
Flag for relative error #580
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
51b6fd0
Added flag for absolute error
varunagrawal c68a647
add test
varunagrawal 326957b
cleaner assertion
varunagrawal 1fd0e57
Better fkag naming, and more docs
varunagrawal 50643be
Merge branch 'develop' into fix/numerical-error
varunagrawal 0737a45
better flag name and docs
varunagrawal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there also be a check that
absolute==true
for the absolute test case?e.g.
a = 0.1
b = 0.2
tol = 0.5
absolute = false
should return false, but instead will return true.
I would propose line 65 to be something like
else if ( absolute && abs(a - b) <= tol )
since the case "when comparing numbers near zero" is covered by the previous test case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually on second thought this might be easier to read if it went something like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should return
true
right? The equality check is more of switch-case rather than explicit absolute and relative error comparisons. The issue is that the flag is poorly named, it should be something like "check_relative" which means that we are also including a relative error check. Thanks for pointing that out (and this is why, kids, you do code-review).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's important to think that this is a general equality check, which is why we have a separate
equal_with_abs_tol
function.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh gotcha!
This is nitpicky but
check_relative
implies to me that, whencheck_relative=true
, it has to pass both absolute and relative checks in order to return true. i.e., it will check absolute, and if it passes, then it will also check relative. This is in contrast to the actual behavior which is that whencheck_relative=true
, then either absolute or relative passing will pass the test and return true.Possibly something like "allow_relative" or something? Or maybe negating: "disable_relative"??? Or maybe just clarifying the docstring in
Vector.h
: "...flag, if true, will consider 2 values to be equal if relative error is within tolerance even if absolute error is not. If this flag is false, false, 2 values will only be considered equal if their absolute error is within tolerance. By default ..."Also, might as well use the
@param
docstring notation?Again, sorry this is nitpicky.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh gotcha!
This is nitpicky but
check_relative
implies to me that, whencheck_relative=true
, it has to pass both absolute and relative checks in order to return true. i.e., it will check absolute, and if it passes, then it will also check relative. This is in contrast to the actual behavior which is that whencheck_relative=true
, then either absolute or relative passing will pass the test and return true.Possibly something like "allow_relative" or something? Or maybe negating: "disable_relative"??? Or maybe just clarifying the docstring in
Vector.h
: "...flag, if true, will consider 2 values to be equal if relative error is within tolerance even if absolute error is not. If this flag is false, false, 2 values will only be considered equal if their absolute error is within tolerance. By default ..."Also, might as well use the
@param
docstring notation?Again, sorry this is nitpicky.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No this is great. If the flag name doesn't make sense now, no way is it going to make sense to someone 3 years from today.
I like allow_relative but I'm not sure if it describes what you said amply. Perhaps something like
check_relative_error_also
, but that's just crazy long (or is it?).Guess the better thing is to update the docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for being late in the game, but I think
require_rel
is probably a good name for this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's actually the opposite of
require_rel
, since will always return true if the absolute error is within tolerance, but it will also return true if the absolute error is out of tolerance but the relative error is within tolerance. In other words, it is giving you the option of relative error in addition to the default behavior of absolute error. So it would be more like,!require_absolute
?I kind of like
check_relative_error_also
😂 🤷♂️or
permit_relative_match
or something? 🤷♂️There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the flag name to
check_relative_also
and made updates to the docs. Running local tests before pushing. 🙂