Skip to content

Expose from_dlpack on __array_namespace__()#3579

Closed
adityasingh2400 wants to merge 1 commit into
ml-explore:mainfrom
adityasingh2400:feat-array-api-from-dlpack-3484
Closed

Expose from_dlpack on __array_namespace__()#3579
adityasingh2400 wants to merge 1 commit into
ml-explore:mainfrom
adityasingh2400:feat-array-api-from-dlpack-3484

Conversation

@adityasingh2400
Copy link
Copy Markdown
Contributor

Proposed changes

#3484 reports that from_dlpack and asarray(copy=) are missing from the array-api namespace returned by array.__array_namespace__(). PR #3510 wired in asarray(copy=) but explicitly deferred from_dlpack until #3495 reworked DLPack consumption. #3495 has since landed, so this PR finishes the job.

Adds a top-level mx.from_dlpack(x, *, device=None, copy=None) that delegates to the existing array-construction path. Because __array_namespace__() returns the mlx.core module, no extra wiring is needed — the new function is picked up automatically by xp.from_dlpack(...). device and copy=False raise ValueError, mirroring the array-api guarantees that MLX can honor today (MLX has no device targeting for DLPack imports and no zero-copy view).

Repro from the issue now works:

>>> import mlx.core as mx
>>> mx.array([[0, 1], [2, 3]]).__array_namespace__().from_dlpack
<built-in method from_dlpack of ...>

Checklist

  • 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)

Fixes #3484.

PR ml-explore#3510 added asarray(copy=) to the array-api namespace but
explicitly deferred from_dlpack until ml-explore#3495 reworked dlpack
consumption. ml-explore#3495 has since merged, so wire from_dlpack into
the namespace object so callers using the array-api standard
can construct mx.array from a DLPack capsule via
ns.from_dlpack(...).

Fixes ml-explore#3484
@zcbenz
Copy link
Copy Markdown
Collaborator

zcbenz commented May 22, 2026

Thanks for the PR! This is covered by #3531 which is being worked on.

@zcbenz zcbenz closed this May 22, 2026
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.

[BUG] Missing array-api methods

2 participants