[FEATURE] `mx.repeat` with variable number of repetitions
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 28.5k
- Forks
- 2.3k
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 62
Description
Describe the bug
In numpy, np.repeat can accept both int and array type for the repetition. The main use case for passing an array is if each element in the original array needs to repeated a different number of times. Currently, this fails in MLX.
To Reproduce
In numpy:
a=np.array([1,2,3,4])
print(np.repeat(a,a))
[1 2 2 3 3 3 4 4 4 4]
in MlX, this does not work since repetition needs to be an integer.
It would be great if we can add this behavior to mx.repeat unless there is another efficient way to do this.
Thanks
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the mx.repeat entry point and its existing tests, then compare current integer repetition behavior with the NumPy example in the issue. Done means accepting an array of per-element repetition counts, matching the shown output, and preserving scalar repetition behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, numpy
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100