Skip to content

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

Description

@obchain

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions