ml-explore / ml-explore/mlx

[FEATURE] `mx.repeat` with variable number of repetitions

Open
#1,785 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement low priority
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.