Skip to content

Fix dpnp.tensor.expm1 handling of complex(+-0, 0) #2926

Open
vlad-perevezentsev wants to merge 3 commits into
masterfrom
fix_expm1_complex
Open

Fix dpnp.tensor.expm1 handling of complex(+-0, 0) #2926
vlad-perevezentsev wants to merge 3 commits into
masterfrom
fix_expm1_complex

Conversation

@vlad-perevezentsev
Copy link
Copy Markdown
Contributor

This PR proposes to fix issue #2878 where dpnp.tensor.expm1(complex(-0.0, 0.0)) returned -0.0 + 0.0j on CPU instead of 0.0 + 0.0j as required by the Array API specification

The fix adds an explicit special-case branch for complex(±0, 0) in expm1.hpp so CPU and GPU behavior are now consistent and compliant with the specification.

Also test_expm1_special_cases test was extended to cover complex(-0.0, 0.0)

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • Have you added documentation for your changes, if necessary?
  • Have you added your changes to the changelog?

@github-actions
Copy link
Copy Markdown
Contributor

View rendered docs @ https://intelpython.github.io/dpnp/pull/2926/index.html

Y = dpt.asnumpy(dpt.expm1(X))
assert_allclose(Y, res, atol=tol, rtol=tol)

# assert_allclose treats +0 == -0
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.

do we need to validate the sign in other cases also when imag=0.0 ?

@coveralls
Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 78.248%. remained the same — fix_expm1_complex into master

@github-actions
Copy link
Copy Markdown
Contributor

Array API standard conformance tests for dpnp=0.21.0dev0=py313h509198e_43 ran successfully.
Passed: 1358
Failed: 2
Skipped: 16

@vlad-perevezentsev vlad-perevezentsev linked an issue May 19, 2026 that may be closed by this pull request
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.

expm1 returns wrong result for -0 + 0 j on CPU

3 participants