Skip to content

Add mlx support - #31151

Merged
jklymak merged 2 commits into
matplotlib:mainfrom
lzqlzzq:add-mlx-support
Feb 14, 2026
Merged

jklymak merged 2 commits into
matplotlib:mainfrom
lzqlzzq:add-mlx-support

Conversation

@lzqlzzq

@lzqlzzq lzqlzzq commented Feb 13, 2026

Copy link
Copy Markdown
Contributor

PR summary

This PR may closes #31149. The modification goes:

  • adding _is_mlx_array for detecting mlx array type. MLX is a numpy-like array library with apple silicon nativeness.
  • modify _unpack_to_numpy function for a or branch where np.asarray may convert mlx.core.array into np.ndarray.

The figure is proved to be plotted:
Pasted Graphic 2

PR checklist

@github-actions

Copy link
Copy Markdown

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide.
Please let us know if (and how) you use AI, it will help us give you better feedback on your PR.

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@jklymak
jklymak merged commit 78c9f7e into matplotlib:main Feb 14, 2026
33 of 40 checks passed
@jklymak

jklymak commented Feb 14, 2026

Copy link
Copy Markdown
Member

I still think there is a more fundamental solution than whitelisting a bunch of libraries, but...

@rcomer rcomer added this to the v3.11.0 milestone Feb 14, 2026
@timhoffm

Copy link
Copy Markdown
Member

I still think there is a more fundamental solution than whitelisting a bunch of libraries, but...

@jklymak In a simple world we should be able to unconditionally do np.asarray. However, it’s my understanding from the previous discussions that this could accidentally strip unit information. The whitelisting of array libraries was the defensive solution to add support for them without breaking anybody else. The alternative is either dropping support for some unit frameworks or blacklisting them, so that they don’t get converted.

@jklymak

jklymak commented Feb 15, 2026

Copy link
Copy Markdown
Member

I agree that is the current state, however, I still think

  • check if object is recognized by units: yes send whole object
  • check if can be made array:
    • check if contents are recognized by units: yes send whole array;
    • check if contents are just numpy types: yes send whole array.
  • error.

Seems like it should work? I don't understand why it doesn't, but I seem to recall somehow pint fails with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ENH]: Improve compatibility with array-like objects implementing __array__ (e.g. MLX arrays)

4 participants