Support indexing with any type which implmented __index__#3210
Support indexing with any type which implmented __index__#3210angeloskath merged 5 commits intoml-explore:mainfrom
__index__#3210Conversation
zcbenz
left a comment
There was a problem hiding this comment.
Can you fix the linting error? The code looks good to me.
angeloskath
left a comment
There was a problem hiding this comment.
Numpy arrays and mlx arrays do not implement __index__ so no need for the extra checks.
| } | ||
| if (!PyIndex_Check(obj.ptr())) { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
I think this should simply be return PyIndex_Check(obj.ptr()) && !nb::isinstance<nb::bool_>(obj);
|
Hi @angeloskath thank you for your review, but numpy has implmeneted Even the And there is also a test case for this: https://github.com/ml-explore/mlx/blob/main/python/tests/test_array.py#L2065 Simplify the code will break it: |
angeloskath
left a comment
There was a problem hiding this comment.
Hm sorry about the noise. It 's so weird cause I explicitly tested it but I guess it was too late and I confused the exceptions.
Proposed changes
Any type which implemented
__index__can be used to indexing mlx array, so we can use numpy scalar to indexing array.boolis not supported also it implemented__index__(actually,boolis a subclass ofint) because it's to quirky.Close: #2710
Checklist
Put an
xin the boxes that apply.pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes