Skip to content

[BUG] Complex vjps are wrong for arcsin/arccos/arctan/arcsinh/arccosh/arctanh (missing conjugate) #3778

Closed

Description

@obchain

Describe the bug

The inverse trigonometric / hyperbolic ops return the wrong gradient for complex inputs: their vjp delegates to their jvp, so the conjugate is dropped. For a holomorphic f the vjp must be cotangent * conj(f'(z)).

Affected: arccos, arccosh, arcsin, arcsinh, arctan, arctanh.

This is the same issue fixed for square/sin/tanh/… in #3766.

To Reproduce

import mlx.core as mx
z = mx.array(0.3 + 0.2j, mx.complex64)
g = mx.array(1.0 + 1.0j, mx.complex64)
vjp = mx.vjp(mx.arctan, [z], [g])[1][0]
expected = g * mx.conj(1 / (1 + z**2))   # cotangent * conj(f'(z))
print(vjp, expected)   # differ

Expected behavior

vjp == cotangent * conj(f'(z)), consistent with mx.exp/mx.log and finite differences.

Desktop

  • OS: macOS
  • Version: main (0.32.0.dev)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions