Skip to content

Fix complex_exp special values for infinite real part - #119

Open
ahlag wants to merge 1 commit into
pearu:mainfrom
ahlag:complex-exp-inf
Open

ahlag wants to merge 1 commit into
pearu:mainfrom
ahlag:complex-exp-inf

Conversation

@ahlag

@ahlag ahlag commented Oct 16, 2026

Copy link
Copy Markdown

This PR fixes incorrect handling of complex exponentials in complex_exp, where inputs such as -inf ± inf·j, -inf + nan·j, inf ± inf·j, and inf + nan·j currently return nan+nanj. The updated implementation handles these special cases according to C99 Annex G.6.3.1 and the Python Array API specification, producing the expected signed zero, infinity, and NaN components. Since the mpmath reference implementation used by the tests does not yet handle these cases correctly, the expected values are temporarily special-cased until mpmath/mpmath#1177 is released. This change also addresses the issues reported in tensorflow#128988 and llvm#232791.

Return 0 + 0j for exp(-inf + y*I) and inf + nan*I for exp(inf + y*I)
when y is inf or nan, as in C99 Annex G, instead of nan + nan*I. Use
the same values in the mpmath reference until mpmath/mpmath#1177 is
released, and regenerate the exp results.
@ahlag

ahlag commented Oct 23, 2026

Copy link
Copy Markdown
Author

@pearu Gentle ping on this one when you have time. openxla/stablehlo#3039 depends on it: the reviewer there will approve once this is merged and the .td file is regenerated. Thanks!

@ahlag

ahlag commented Nov 12, 2026

Copy link
Copy Markdown
Author

@pearu friendly ping. CI for this PR is waiting for approval (first-time contributor), so it hasn't run yet. Happy to change anything. The mpmath fix (mpmath/mpmath#1177) is merged but not released, so the expected values stay special-cased for now.

copybara-service Bot pushed a commit to openxla/stablehlo that referenced this pull request Nov 17, 2026
Imported from GitHub PR #3039

#ai-generated

This PR fixes incorrect handling of complex exponentials in StableHLO, where inputs such as `-inf ± inf·j`, `-inf + nan·j`, `inf ± inf·j`, and `inf + nan·j` produce `nan+nanj` instead of the expected results defined by C99 Annex G.6.3.1 and the Python Array API specification. To align with the corresponding functional_algorithms fix (pearu/functional_algorithms#119), the generated `.td` file and the two exp test samples were manually updated. These files can be regenerated once the upstream functional_algorithms fix is released. This change addresses tensorflow/tensorflow#128988 and llvm/llvm-project#232791. Testing confirms that `check-stablehlo-tests` passes with the fix, while both exp sample files fail without it.

Copybara import of the project:

--
a946213 by ahlag <theeahlag@gmail.com>:

Fix complex exp special values for infinite real part

exp(-inf + I*y) returned nan + nan*I instead of 0 for infinite or nan y,
and exp(inf + I*y) returned nan instead of inf for the real part, as
specified in C99 Annex G. Update the exp reference samples accordingly.

Merging this change closes #3039

COPYBARA_INTEGRATE_REVIEW=#3039 from ahlag:complex-exp-inf a946213
PiperOrigin-RevId: 1024088792
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