[BUG] mx.expm1 is wrong for complex inputs (discards imaginary part)
Open
Beginner friendly
Nobody has claimed this yet.
bug
- Dominant language
- C++
- Stars
- 28.5k
- Forks
- 2.3k
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 62
Description
Describe the bug
mx.expm1 returns wrong results for complex inputs: it operates on the real part and discards the imaginary part. The CPU backend uses std::expm1, which has no complex overload.
import mlx.core as mx
z = mx.array([0.5 + 0.7j])
print(mx.expm1(z)) # [0.6487+0j] == expm1(0.5), wrong
print(mx.exp(z) - 1) # [0.261+1.062j] correct
mx.log1p and mx.log2 already special-case complex; expm1 was missed.
Expected behavior
mx.expm1(z) == mx.exp(z) - 1 for complex z.
Desktop
- OS: macOS
- Version: main (0.32.0.dev)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the CPU backend implementation of mx.expm1 and compare its handling with the special cases already used by mx.log1p and mx.log2. Confirm that complex inputs preserve their imaginary part and that mx.expm1(z) matches mx.exp(z) - 1 for the reported example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100