Skip to content

Conversation

mhucka
Copy link
Contributor

@mhucka mhucka commented Aug 25, 2025

Changes:

  1. isclose() now accepts relative and absolute tolerances. This allows for more precise control over the comparison, just like in NumPy.
  2. Adjusted the comparison logic. 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.

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`.
@mhucka mhucka marked this pull request as ready for review August 25, 2025 21:15
@mhucka mhucka added the area/health Involves code and/or project health label Aug 25, 2025
Comment on lines +630 to +631
rel_tol(float): Relative tolerance.
abs_tol(float): Absolute tolerance.
Copy link
Collaborator

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):
Copy link
Collaborator

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

Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/health Involves code and/or project health
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants