Skip to content

Add signbit operation - #4959

Merged
zcbenz merged 9 commits into
ml-explore:mainfrom
lipefree:feat/signbit
Nov 28, 2026
Merged

zcbenz merged 9 commits into
ml-explore:mainfrom
lipefree:feat/signbit

Conversation

@lipefree

@lipefree lipefree commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Add the signbit operation for cpu, metal and cuda as tracked in #4909, following the specification or the Python Array API standard. Check whether the sign bit is set for each element, including negative zero and NaNs with a negative sign bit.

import mlx.core as mx

a = mx.array([3.0, -3.0, 0.0, -0.0, float("nan"), -float("nan")])
print(mx.signbit(a).tolist())
# [False, True, False, True, False, True]

cpu implemention support integer, boolean, float16, bfloat16, float32 and float64.
metal implemention support integer, boolean, float16, bfloat16, float32.

We reject complex inputs for this function.

Tested on CPU and Metal. The CUDA implementation has not been compiled or tested because I don’t have access to CUDA hardware.

  • ☑️ I understand it is strictly prohibited to use AI to write PR description
  • AI usage disclosure: co-developed with coding agent for implementing the operation, building the project and running the tests

@lipefree
lipefree force-pushed the feat/signbit branch 3 times, most recently from 53791e6 to 2752a50 Compare November 24, 2026 22:00
@lipefree
lipefree marked this pull request as ready for review November 25, 2026 00:56

@zcbenz zcbenz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind rebasing the PR on main branch to solve the conflict with #4953?

@lipefree

Copy link
Copy Markdown
Contributor Author

@zcbenz I rebased on main branch 👍

@zcbenz
zcbenz merged commit 1db6596 into ml-explore:main Nov 28, 2026
24 checks passed
@lipefree

Copy link
Copy Markdown
Contributor Author

@zcbenz Thank you very much for fixing the CI and merging this!

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.

2 participants