mlx icon indicating copy to clipboard operation
mlx copied to clipboard

[BUG] Indexing inconsistencies

Open dionhaefner opened this issue 1 year ago • 1 comments

Describe the bug

  • mlx.core.newaxis is missing:
>>> mx.array([1])[mx.newaxis]
AttributeError: module 'mlx.core' has no attribute 'newaxis'
  • Cannot index with Ellipsis / ...:
>>> mx.array([1])[...]
ValueError: Cannot index mlx array using the given type.

To Reproduce

See above.

Expected behavior

Consistency with NumPy.

Desktop (please complete the following information): v0.0.7

dionhaefner avatar Jan 04 '24 09:01 dionhaefner

Cool, I don't mind adding that though I find it a bit odd how numpy has different syntax for the same thing.

In mx we went with None for adding new axes (which numpy aslo has). So you can do:

mx.array([1])[None]`

I think for this we could bind a little axis type in pybind11 and then use it in the same place we us None.

awni avatar Jan 04 '24 14:01 awni

No need. np.newaxis is an alias for None, meaning that np.newaxis is None returns True. All we have to do is add an alias as mx.newaxis = None if we want full numpy compatibility.

angeloskath avatar Jan 09 '24 02:01 angeloskath

@awni @angeloskath Hi, can I pick this up?

AvikantSrivastava avatar Jan 10 '24 12:01 AvikantSrivastava

Yes sure!

awni avatar Jan 10 '24 14:01 awni

@awni should I add all the constant that numpy offers? https://numpy.org/doc/stable/reference/constants.html

I was thinking of adding a init_constants(m) in mlx/python/src/mlx.cpp

AvikantSrivastava avatar Jan 10 '24 14:01 AvikantSrivastava

@awni @angeloskath fixed in https://github.com/ml-explore/mlx/pull/428

can you folks take a look at the PR

AvikantSrivastava avatar Jan 11 '24 10:01 AvikantSrivastava

Sent a comment, but o/w looks great, thanks for adding thos!

awni avatar Jan 11 '24 14:01 awni