Skip to content

SweepFormula: treat non-finite literals (NaN/Inf/-inf) as numeric operands - #2762

Draft
t-b with Copilot wants to merge 5 commits into
mainfrom
copilot/issue-1863-fix-memory-leak
Draft

SweepFormula: treat non-finite literals (NaN/Inf/-inf) as numeric operands#2762
t-b with Copilot wants to merge 5 commits into
mainfrom
copilot/issue-1863-fix-memory-leak

Conversation

Copilot AI commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Thanks for opening a PR in MIES ✨!

  • Code can only be merged if the continous integration tests pass
  • Please ensure that the branch is named correctly. See
    here for the detailed explanation.

Description

Bare non-finite literals as operands of primitive operations (1 - NaN, 1 - inf, ...) aborted with Operand for - must be numeric.. JSON can't hold non-finite numbers, so the parser keeps them as strings; the executor now coerces them to numeric at operation time — matching how arrays like [1, "NaN"] already behave.

1 - NaN   // NaN
1 - inf   // -inf
1 - -inf  // inf
1 / inf   // 0

Changes:

  • Executor — promoted SFE_ConvertNonFiniteElements to file-external and added an empty-input guard, so the existing inf/-inf/NaN/-NaN recognition is the single source of truth.
  • Operations — added SFO_ConvertNonFiniteText; the primitive-op dispatcher SFO_IndexOverDataSetsForPrimitiveOperation converts both operands before applying +, -, *, /. Text that isn't purely non-finite is left untouched (still errors as before).
  • Tests — re-enabled TestNonFiniteValuesPrimitiveOperations covering 1±NaN, 1±inf, 1--inf, 1*inf, 1/inf.
  • Docs — noted non-finite literals as valid operands of the primitive operations in SweepFormula.rst.

Copilot AI and others added 2 commits August 10, 2026 18:27
Co-authored-by: t-b <1185677+t-b@users.noreply.github.com>
Co-authored-by: t-b <1185677+t-b@users.noreply.github.com>
Copilot AI assigned Copilot and t-b Aug 10, 2026
Copilot AI lite review requested due to automatic review settings August 10, 2026 18:31
Copilot finished work on behalf of t-b August 10, 2026 18:31
Copilot AI requested a review from t-b August 10, 2026 18:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates SweepFormula’s primitive operation execution so that bare non-finite literals (NaN, inf, -inf, …) that are parsed as strings are coerced to numeric operands at operation time, aligning behavior with existing mixed-array handling.

Changes:

  • Exposes and reuses the executor’s non-finite conversion helper (with an added empty-input guard) as the single conversion implementation.
  • Adds operand-side coercion for primitive operations so +, -, *, / accept bare non-finite literals as numeric operands.
  • Re-enables and expands tests for primitive operations with non-finite literals and documents the behavior in SweepFormula docs.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
Packages/tests/Basic/UTF_SweepFormula.ipf Re-enables primitive-op tests to cover 1±NaN, 1±inf, 1--inf, 1*inf, 1/inf.
Packages/MIES/MIES_SweepFormula_Operations.ipf Coerces per-dataset operands in primitive ops by converting text-only non-finite datasets to numeric waves.
Packages/MIES/MIES_SweepFormula_Executor.ipf Promotes the non-finite conversion helper to file-external and adds an empty-input guard.
Packages/doc/SweepFormula.rst Documents non-finite literals as valid operands for primitive operations.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread Packages/MIES/MIES_SweepFormula_Operations.ipf Outdated
Comment on lines +698 to +701
/// @brief Convert a text wave that consists solely of the non-finite literals inf/-inf/NaN into a numeric wave
///
/// @return numeric wave with the converted values or a null wave reference if at least one element is not a
/// non-finite literal
Comment thread Packages/doc/SweepFormula.rst Outdated
Comment on lines +201 to +203
The non-finite literals `inf`, `-inf` and `NaN` are also accepted as operands of the primitive
operations `+`, `-`, `*` and `/`, so that e.g. `1 - NaN` and `1 - inf` are valid and evaluate them
as numeric values.
Co-authored-by: t-b <1185677+t-b@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 10, 2026 19:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Co-authored-by: t-b <1185677+t-b@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 10, 2026 19:44
Copilot finished work on behalf of t-b August 10, 2026 19:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Suppressed comments (3)

Packages/MIES/MIES_SweepFormula_Executor.ipf:701

  • The doc comment lists only inf/-inf/NaN, but the implementation also recognizes -NaN (see SFE_ConvertNonFiniteElementsImpl). Please include -NaN in the comment to avoid misleading future readers.
/// @brief Convert a text wave that consists solely of the non-finite literals inf/-inf/NaN into a numeric wave
///
/// @return numeric wave with the converted values or a null wave reference if at least one element is not a
///         non-finite literal

Packages/MIES/MIES_SweepFormula_Operations.ipf:2574

  • The docstring says only inf/-inf/NaN, but the conversion routine also supports -NaN and the user-facing docs mention it. Please update this comment so the accepted literals are accurately documented.
/// @brief Convert a dataset that consists solely of the non-finite literals inf/-inf/NaN into a numeric wave
///
/// This allows primitive operations like `1 - NaN` or `1 - inf` where a non-finite value is entered as bare
/// literal and is therefore kept as string by the parser. Returns the input unchanged if it is not textual or if
/// it contains at least one element that is not a non-finite literal.

Packages/MIES/MIES_SweepFormula_Helpers.ipf:70

  • This helper comment mentions only inf/-inf/NaN, but SFE_ConvertNonFiniteElements also accepts -NaN. Keeping the list in sync with the conversion logic avoids confusion.
		// the non-finite literals inf/-inf/NaN are kept as text by the parser (see #1863),
		// coerce them to numeric so they are accepted wherever a numeric argument is taken

@t-b

t-b commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

@copilot The case where the formula is just one of inf/-inf/NaN like

Inf

gives "cannot plot a single text wave" whereas this works with just 1234. Please fix that.

Co-authored-by: t-b <1185677+t-b@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 12, 2026 17:10

Copilot AI commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

@copilot The case where the formula is just one of inf/-inf/NaN like

...

Addressed in 0a856c3. Standalone inf/-inf/NaN/-NaN formulas are now coerced to numeric results at top-level execution as well, and I added focused coverage for those scalar cases.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Suppressed comments (3)

Packages/MIES/MIES_SweepFormula_Operations.ipf:2604

  • This comment says inf/-inf/NaN, but "-NaN" is also treated as a non-finite literal by SFE_ConvertNonFiniteElements. Please include -NaN to match the actual accepted set.
	// treat the non-finite literals inf/-inf/NaN as numeric operands, see #1863

Packages/MIES/MIES_SweepFormula_Helpers.ipf:70

  • The comment mentions inf/-inf/NaN, but the implementation also accepts "-NaN" (see SFE_ConvertNonFiniteElementsImpl). Please include -NaN here to keep the documentation accurate.
		// the non-finite literals inf/-inf/NaN are kept as text by the parser (see #1863),
		// coerce them to numeric so they are accepted wherever a numeric argument is taken

Packages/doc/SweepFormula.rst:201

  • The array-evaluation docs currently state that ["NaN"] returns a text wave. With this PR, JSON strings equal to non-finite literals are coerced to numeric (via SFE_FormulaExecutorStringOrVariable), so ["NaN"] will evaluate to a numeric wave {NaN}. Please update this example/text to match the new behavior.
The array evaluation supports numeric and text data. The interpretation of the JSON arrays as
text data is preferred. This means that `["NaN"]` returns a one element text wave `{"NaN"}`,
whereas `[1, "NaN"]` returns a two element numeric wave `{1, NaN}`. If one element can not be
parsed as string then it is assumed that the array contains numeric data.
The non-finite literals `inf`, `-inf`, `NaN` and `-NaN` are also accepted as standalone expressions and as operands

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.

3 participants