Repository navigation
Conversation
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.
This was referenced Oct 16, 2026
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! |
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes incorrect handling of complex exponentials in
complex_exp, where inputs such as-inf ± inf·j,-inf + nan·j,inf ± inf·j, andinf + nan·jcurrently returnnan+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.