Skip to content

Add copy keyword to mx.asarray#3510

Open
eyupcanakman wants to merge 1 commit into
ml-explore:mainfrom
eyupcanakman:fix/asarray-copy-kwarg-3484
Open

Add copy keyword to mx.asarray#3510
eyupcanakman wants to merge 1 commit into
ml-explore:mainfrom
eyupcanakman:fix/asarray-copy-kwarg-3484

Conversation

@eyupcanakman
Copy link
Copy Markdown

@eyupcanakman eyupcanakman commented May 10, 2026

Proposed changes

mx.asarray doesn't accept the copy keyword from the array-API spec. References #3484.

This adds copy as a keyword-only argument. MLX has no in-place operations, so a non-copying conversion isn't meaningful: copy=False raises ValueError, and copy=True or unspecified behave the same as before.

The from_dlpack half of #3484 is left out, since PR #3495 reworks dlpack consumption through the mx.array(...) constructor and the namespace wiring depends on that landing.

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

Copy link
Copy Markdown
Collaborator

@zcbenz zcbenz left a comment

Choose a reason for hiding this comment

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

The copy parameter only makes sense if the framework supports in-place operation and you want to make a deep copy whose content would stay unchanged when the original copied array got an in-place update. But since MLX has no in-place operation and the supposed use case would never happen.

So I think the best way to support copy parameter is to simply throw when copy=False is passed and return create_array(a, dtype) otherwise like before. Because copy=False means shallow-copy which makes no sense in MLX, and code using copy=True|None would stay semantically correct.

@eyupcanakman eyupcanakman force-pushed the fix/asarray-copy-kwarg-3484 branch from 074ec2b to 7e60107 Compare May 12, 2026 16:19
@eyupcanakman
Copy link
Copy Markdown
Author

Makes sense, reworked it that way: copy=False raises now, copy=True and the default go through create_array like before.

Copy link
Copy Markdown
Collaborator

@zcbenz zcbenz left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks!

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