Closed
Conversation
Member
|
There is already a PR implementing the exact same fix #3210, feel free to comment there if there is something that isn't supported or can be improved. It has also been several PRs that already had PRs submitted with the exact same fix (a lot of which I merged because they were small). Please do a search and contribute to the existing PRs before submitting a new one. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Proposed changes
#2710
indexing with numpy integer scalars (
np.int64(1),np.int32(2), etc.) throws"Cannot index mlx array using the given type" because the indexing code only
checks for Python's built-in
intvianb::isinstance<nb::int_>. numpyinteger scalars aren't
intsubclasses but they do implement__index__(PEP 357).
the fix replaces all
nb::isinstance<nb::int_>checks in the indexing pathwith a helper that uses
PyIndex_Check, which matches any object implementing__index__. this covers direct indexing (x[np.int64(1)]), slicing(
x[np.int64(1):]), tuple indexing (x[np.int64(0), np.int64(1)]), andassignment through all the same paths.
Checklist
pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes