ml-explore / ml-explore/mlx

[BUG] mx.expm1 is wrong for complex inputs (discards imaginary part)

Open Beginner friendly
#3,759 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.