-
Notifications
You must be signed in to change notification settings - Fork 401
Fix #764: wrong SymbolicOperator.isclose() result #1114
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: master
Are you sure you want to change the base?
Conversation
Changes: 1. `isclose()` now accepts relative and absolute tolerances. This allows for more precise control over the comparison, just like in NumPy. 2. The comparison logic was corrected. The old implementation used a single tolerance value that it scaled in a way that could produce incorrect results. The new logic uses a common formula for checking if 1 numbers are close: ``` abs(a - b) <= abs_tol + rel_tol * max(abs(a), abs(b)) ``` 3. Updated `__eq__` in `SymbolicOperator` to use the tolerance values. 4. Added a new test `symbolic_operator_test.py`.
rel_tol(float): Relative tolerance. | ||
abs_tol(float): Absolute tolerance. |
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.
consider rtol and atol for consistency with numpy/scipy
@@ -618,15 +618,17 @@ def __next__(self): | |||
term, coefficient = next(self._iter) | |||
return self.__class__(term=term, coefficient=coefficient) | |||
|
|||
def isclose(self, other, tol=EQ_TOLERANCE): | |||
def isclose(self, other, rel_tol=EQ_TOLERANCE, abs_tol=EQ_TOLERANCE): |
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.
this is technically a breaking API change. are we ok with that? weigh confusion vs. code compatibility to keeping one of them named tol
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.
Yeah, maybe we could keep 'tol' as a deprecated parameter and set atol=tol if it exists.
gentle ping |
Per comments in PR review, this renames `rel_tol` and `abs_tol` to be `rtol` and `atol`, respectively, as well ask keeps the previous `tol` parameter but marks it as deprecated.
Changes:
isclose()
now accepts relative and absolute tolerances. This allows for more precise control over the comparison, just like in NumPy.__eq__
inSymbolicOperator
to use the tolerance values.symbolic_operator_test.py
.