-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Add an error margin when comparing floats. #129721
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
base: main
Are you sure you want to change the base?
Add an error margin when comparing floats. #129721
Conversation
Pinging @elastic/es-storage-engine (Team:StorageEngine) |
} | ||
|
||
for (int i = 0; i < normalizedActual.size(); i++) { | ||
if (floatsEquals(normalizedActual.get(i), normalizedExpected.get(i))) { |
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.
So if floatsEquals(...)
returns true then there is no match? Maybe rename floatsEquals(...)
to floatsNoEquals(...)
?
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.
oh boy, my bad. Actually I prefer to keep it floatsEquals and fix the code because its more intuitive.
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.
also good with me 👍
...work/src/main/java/org/elasticsearch/datageneration/matchers/source/DynamicFieldMatcher.java
Outdated
Show resolved
Hide resolved
Thank you @martijnvg for the review, such an oversight the method name and implementation 🙃 . I run the test locally with What do you think? |
Yes, that should give good confidence. |
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.
LGTM 👍
if (normalizedActual.size() != normalizedExpected.size()) { | ||
return noMatchSupplier.get(); | ||
} | ||
|
||
for (int i = 0; i < normalizedActual.size(); i++) { | ||
if (floatEquals(normalizedActual.get(i), normalizedExpected.get(i)) == false) { | ||
return noMatchSupplier.get(); | ||
} | ||
} |
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.
Both of these checks are on the normalized lists, which have null values removed. This means if there's an extra null somewhere, or if the null is in a different position between the expected and actual, we wouldn't catch it here. Is this intentional?
We add a margin of error when comparing floats to the
DynamicFieldMatcher
to account for a small loss of accuracy when loading fields from synthetic source.Furthermore, we switched the set to a list to take the order of array elements also into account since it's supported.
Fixes: #129527, #129528, #129529