Skip to content

Reject non-finite function values in second_autocorr_ineq - #7

Merged
HenriqueAssumpcao merged 2 commits into
inter-science:mainfrom
bfs2021:fix/second-autocorr-non-finite
Oct 29, 2026
Merged

HenriqueAssumpcao merged 2 commits into
inter-science:mainfrom
bfs2021:fix/second-autocorr-non-finite

Conversation

@bfs2021

@bfs2021 bfs2021 commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Problem

second_autocorr_ineq/input/evaluate.py accepts NaN / +inf function values and writes a result with "c2": NaN instead of failing. The issue reproducer returns no exception and records the run as completed. Fixes #6.

Root cause

The only input guards are f_values < -1e-6 (False for NaN), np.maximum(f_values, 0.0) (keeps NaN), and norm_1 * norm_inf < 1e-12 (False for NaN), so non-finite values pass every check and reach the JSON output.

Fix

Reject non-finite values with np.isfinite(f_values).all() before the non-negativity check. -inf was previously rejected indirectly as negative; it now fails with the same explicit "must be finite" error.

Testing

  • Added tests/test_second_autocorr_ineq_evaluate.py: NaN, +inf and -inf programs raise ValueError and write no results file; a finite function still evaluates (c2 = 2/3 for [1, 1, 1, 1]).
  • pytest tests/test_second_autocorr_ineq_evaluate.py → 4 passed.
  • The issue's original reproducer now raises ValueError: Function values must be finite. instead of writing NaN.

The evaluator only checked for negative values, so NaN and infinity passed every guard (NaN comparisons are False) and were written to the results file as a completed c2. Reject non-finite values before the non-negativity check, with regression tests for NaN, +inf and -inf.
@HenriqueAssumpcao

Copy link
Copy Markdown
Collaborator

Thanks for the contribution! Would you mind updating the PR to include just the new test? PR #8 already applies the same fix.

Cheers!

@bfs2021

bfs2021 commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

Done — merged main (which now carries the guard from #8), so the PR is test-only: tests/test_second_autocorr_ineq_evaluate.py, 78 lines, no source changes. It covers NaN, +inf and -inf rejection plus a finite control case ([1.0]*10 → c2 = 2/3); 4 passed locally.

@HenriqueAssumpcao
HenriqueAssumpcao merged commit 9897ef1 into inter-science:main Oct 29, 2026
2 checks passed
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.

second_autocorr_ineq evaluate.py accepts NaN/+inf sequences and writes a NaN result

2 participants