Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#4560·mlx

[BUG] `__setitem__` with a bare ellipsis fails to broadcast leading singleton dimensions

Author: shaeantoineCreated Sep 25, 2026Updated Sep 25, 2026

☑️ I understand it is strictly prohibited to use AI to write issues.

Describe the bug __setitem__ has inconsistent behavior when using a bare ellipsis. When I attempted to broadcast an array with leading singleton dimensions (for instance (1,3) to a (3,)), __setitem__ threw a value error when using a bare ellipsis (a[...]). However, I don't encounter the same bug if I use a tuple wrapped ellipsis (a[(...,)]) or full slice (a[:]). All three should have consistent behavior.

To Reproduce

python
>>> import mlx.core as mx
>>> a = mx.arange(3)
>>> a[...] = mx.array([[1, 2, 3]])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    a[...] = mx.array([[1, 2, 3]])
    ~^^^^^
ValueError: Cannot broadcast array of shape (1,3) into shape (3).
>>> a[(...,)] = mx.array([[1, 2, 3]]) 
>>> a
array([1, 2, 3], dtype=int32)
>>> a[:] = mx.array([[1, 2, 3]]) 
>>> a
array([1, 2, 3], dtype=int32)

Expected behavior __setitem__ with a bare ellipsis should have consistent behavior with a full slice or tuple based ellipsis. The leading singleton dimensions should be able to be squeezed since there is no loss of information. So I should be able to do the following:

python
>>> import mlx.core as mx
>>> a = mx.arange(3)
>>> a[...] = mx.array([[1, 2, 3]])
>>> a
array([1, 2, 3], dtype=int32)
>>> a[(...,)] = mx.array([[1, 2, 3]]) 
>>> a
array([1, 2, 3], dtype=int32)
>>> a[:] = mx.array([[1, 2, 3]]) 
>>> a
array([1, 2, 3], dtype=int32)

Desktop and MLX Version:

  • OS Version: MacOS 26.5.2
  • MLX Version: 0.32.2

Additional context This issue was found when reviewing issue #4358 (now closed). That issue was solved by the earlier fix #4314 raised by the error #4313. This issue can be thought of as a remaining edge case from the original problem addressed by these earlier tickets.

Source: ml-explore/mlx

View original on GitHubView discussion on GitHub