mlx icon indicating copy to clipboard operation
mlx copied to clipboard

add support for tile

Open Bahaatbb opened this issue 2 years ago • 1 comments

Proposed changes

np.tile function in mlx as a op mlx.core.tile

Checklist

Put an x in the boxes that apply.

  • [x] I have read the CONTRIBUTING document
  • [x] I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • [x] I have added tests that prove my fix is effective or that my feature works
  • [x] I have updated the necessary documentation (if needed)

Bahaatbb avatar Dec 29 '23 23:12 Bahaatbb

@angeloskath Hey, Happy new year 🎉. sorry if my first implementation is not up for the standards, tho I must say that it is almost the same implementation as numpy. tho, I went back and tried this implementation and hacked together this code using your idea, the below code is just a prototype, to take your approval to proceed.

def tile(arr, repeats):
    d = len(repeats)
    
    if d < arr.ndim:
        repeats = [1] * (arr.ndim - d) + repeats
    else:
        arr = np.expand_dims(arr, axis=tuple(range(d - arr.ndim)))

    for i, rep in enumerate(repeats):
        if rep != 1:
            arr = np.expand_dims(arr, axis=i)
            arr = np.broadcast_to(arr, arr.shape[:i] + (rep,) + arr.shape[i+1:])
            arr = np.reshape(arr, arr.shape[:i] + (-1,) + arr.shape[i+2:])
            
    return arr

Note: I change the implementation code to match python code.

Bahaatbb avatar Dec 31 '23 16:12 Bahaatbb

is this pr stale ?

dc-dc-dc avatar Jan 11 '24 22:01 dc-dc-dc

Sorry, I haven't had the chance to get back to this, I think did what is required @dc-dc-dc . I will close this and look for more in the future.

Bahaatbb avatar Jan 12 '24 12:01 Bahaatbb