Skip to content

Preserve negative zero in CPU Where - #32539

Open
Sylvester Kaczmarek (sylvesterkaczmarek) wants to merge 3 commits into
microsoft:mainfrom
sylvesterkaczmarek:fix/where-negative-zero
Open

Preserve negative zero in CPU Where#32539
Sylvester Kaczmarek (sylvesterkaczmarek) wants to merge 3 commits into
microsoft:mainfrom
sylvesterkaczmarek:fix/where-negative-zero

Conversation

@sylvesterkaczmarek

@sylvesterkaczmarek Sylvester Kaczmarek (sylvesterkaczmarek) commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #32191.

The CPU Where implementation uses zero-filled selection tensors and treats value != 0 as the marker that an element was selected. A selected -0.0 compares equal to the +0.0 sentinel, so its sign bit is lost.

Preserve selected floating-point negative zero while keeping integer and string behavior unchanged. The algorithm comment now describes the signed-zero-aware selection rule.

Testing

  • Float/double regression coverage for direct X selection and broadcast Y selection.
  • The custom verifier checks both equality to zero and the sign bit.
  • Native macOS arm64 Release build completed; all 6 WhereOpTest.* cases passed.

Validation used a combined worktree on current main with the pending QuickGelu, DivMul, and Gelu fixes. This does not claim validation of the full upstream CI matrix.

Copilot AI balanced review requested due to automatic review settings September 10, 2026 09:27
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The custom verifier must also confirm outputs are zero, and the merge documentation should match the new logic.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Preserves floating-point negative zero in CPU Where selection.

Changes:

  • Adds signed-zero-aware merge detection.
  • Adds float/double CPU regression tests.
File summaries
File Description
where_op.cc Preserves selected -0.0.
where_op_test.cc Tests X and broadcast Y paths.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread onnxruntime/test/providers/cpu/tensor/where_op_test.cc
Comment thread onnxruntime/core/providers/cpu/tensor/where_op.cc
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.

Where returns +0.0 for a selected -0.0, on both the X and Y branches (CPU EP)

2 participants