-
Notifications
You must be signed in to change notification settings - Fork 85
Add support for MLX arrays #301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
gabrieldemarmiesse
wants to merge
6
commits into
patrick-kidger:main
from
gabrieldemarmiesse:add_mlx_support
Closed
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f0f9ade
Allow MLX types to be recognized
c7b6529
Formatting
b4dd9aa
Add unit test for mlx
gabrieldemarmiesse efa3116
Updated documentation
gabrieldemarmiesse 76762cb
The type hint is not a subclass of the base type anymore
gabrieldemarmiesse ebb95ff
Merge branch 'main' into add_mlx_support
gabrieldemarmiesse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -617,15 +617,14 @@ def _make_array(x, dim_str, dtype): | |
|
|
||
| if type(out) is tuple: | ||
| array_type, name, dtypes, dims, index_variadic, dim_str = out | ||
| # Nanobind classes can't be a base type | ||
| can_subclass = array_type is Any or "nanobind." in str(type(array_type)) | ||
| metaclass = ( | ||
| _make_metaclass(type) | ||
| if array_type is Any | ||
| else _make_metaclass(type(array_type)) | ||
| _make_metaclass(type) if can_subclass else _make_metaclass(type(array_type)) | ||
| ) | ||
|
|
||
| out = metaclass( | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we skip creating the metaclass too? And have this line just be |
||
| name, | ||
| (AbstractArray,) if array_type is Any else (array_type, AbstractArray), | ||
| (AbstractArray,) if can_subclass else (array_type, AbstractArray), | ||
| dict( | ||
| dtype=dtype, | ||
| array_type=array_type, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,3 +8,4 @@ pytest | |
| pytest-asyncio | ||
| tensorflow | ||
| typeguard<3 | ||
| mlx | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was afraid things might look something like this!
FWIW we could maybe just remove subclassing altogether -- I'm not sure how much this buys us, and we're really threading the needle here to do so -- WDYT?
(I think I might have introduced this subclassing to make things work better when using type annotations with plum, although I might have that wrong. I think that's a use-case that can be supported in other ways, though.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no opinion on the matter. I'll remove the subclassing entirely and see where it goes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only test failing is this one:
test/test_array.py::test_subclass - AssertionError: assert False. Every assertion on this test is failing.I find it strange that a type hint need to be a subclass of a type. If that's not needed, we can remove this completely. How should I proceed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. I think let's go ahead and remove it then!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, I'll let you review one more time!