Skip to content

fix: reject NaN/+inf in numeric settings validation#205

Merged
bodono merged 1 commit into
masterfrom
fix/reject-nan-inf-settings
Apr 22, 2026
Merged

fix: reject NaN/+inf in numeric settings validation#205
bodono merged 1 commit into
masterfrom
fix/reject-nan-inf-settings

Conversation

@bodono

@bodono bodono commented Apr 22, 2026

Copy link
Copy Markdown
Owner

Summary

  • IEEE NaN comparisons always return false, so x <= 0 / x < 0 / x >= 2 let NaN slip through every numeric setting in SCS_init. The solver then runs to completion producing NaN iterates with no error surfaced. SCS core's own validate() has the same gap.
  • scale=+inf additionally triggers a misleading "ScsWork allocation error!" from the linear-system factorization; rho_x=+inf silently produces NaN iterates.
  • Add explicit isnan/isfinite guards in the validation block. scale, rho_x, alpha must now be finite; eps_* and time_limit_secs reject NaN but still accept +inf (semantically meaningful — disables that stopping criterion / time limit).

Repro (before)

sol = scs.solve(data, {"q": [], "l": 2}, scale=float("nan"))
# -> runs to "max_iters reached", x=[nan]
sol = scs.solve(data, {"q": [], "l": 2}, scale=float("inf"))
# -> ValueError: ScsWork allocation error!  (misleading)

After

ValueError: scale must be a positive finite number

Test plan

  • 11 new parametrized tests covering NaN on all 7 float settings, +inf rejection on scale/rho_x/alpha, +inf acceptance on eps_*/time_limit_secs
  • Existing test_scale_zero_raises / test_rho_x_zero_raises regex relaxed to accommodate the updated error string
  • Full suite green (371 passed, 66 skipped)

🤖 Generated with Claude Code

IEEE NaN comparisons always return false, so `x <= 0` / `x < 0` /
`x >= 2` checks silently let NaN slip through every numeric setting
in SCS_init. The solver then runs to completion with garbage iterates
(x = [nan]) and no error surfaces. SCS core's own validate() has the
same gap. +inf on `scale` additionally triggers a misleading
"ScsWork allocation error!" from the linear-system factorization;
+inf on `rho_x` silently produces NaN iterates.

Add explicit isnan/isfinite guards:
 - scale, rho_x, alpha: must be finite (reject NaN and +inf)
 - eps_abs, eps_rel, eps_infeas, time_limit_secs: reject NaN but
   accept +inf, which is semantically meaningful (disables that
   stopping criterion / time limit).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@bodono
bodono merged commit f8319fc into master Apr 22, 2026
34 checks passed
@bodono
bodono deleted the fix/reject-nan-inf-settings branch April 22, 2026 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant