fix(ga): Suppress divide-by-zero warning in NumPy solver #17

Merged
jono merged 1 commits from v0.4.1-dev into main 2025-10-27 16:26:58 +00:00
Owner

The _solve_x_numpy method was correctly using np.where(error == 0, ...) to handle perfect roots. However, NumPy eagerly calculates 1.0 / error for the entire array before applying the where condition, which was causing a RuntimeWarning: divide by zero when a perfect root was found.

This warning was harmless but created unnecessary console noise during testing and use.

This commit wraps the ranks = ... assignments in a with np.errstate(divide='ignore'): block to silence this specific, expected warning. The CUDA kernel is unaffected as its ternary operator already prevents this calculation.

The `_solve_x_numpy` method was correctly using `np.where(error == 0, ...)` to handle perfect roots. However, NumPy eagerly calculates `1.0 / error` for the entire array before applying the `where` condition, which was causing a `RuntimeWarning: divide by zero` when a perfect root was found. This warning was harmless but created unnecessary console noise during testing and use. This commit wraps the `ranks = ...` assignments in a `with np.errstate(divide='ignore'):` block to silence this specific, expected warning. The CUDA kernel is unaffected as its ternary operator already prevents this calculation.
jono added 1 commit 2025-10-27 16:26:26 +00:00
fix(ga): Suppress divide-by-zero warning in NumPy solver
All checks were successful
Publish Python Package to PyPI / deploy (push) Successful in 18s
Run Python Tests / test (3.12) (pull_request) Successful in 12s
Run Python Tests / test (3.10) (pull_request) Successful in 17s
Run Python Tests / test (3.8) (pull_request) Successful in 10s
7c75000637
The `_solve_x_numpy` method was correctly using `np.where(error == 0, ...)` to handle perfect roots. However, NumPy eagerly calculates `1.0 / error` for the entire array before applying the `where` condition, which was causing a `RuntimeWarning: divide by zero` when a perfect root was found.

This warning was harmless but created unnecessary console noise during testing and use.

This commit wraps the `ranks = ...` assignments in a `with np.errstate(divide='ignore'):` block to silence this specific, expected warning. The CUDA kernel is unaffected as its ternary operator already prevents this calculation.
jono merged commit 7c75000637 into main 2025-10-27 16:26:58 +00:00
jono deleted branch v0.4.1-dev 2025-10-27 16:26:58 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: jono/PolySolve#17