mlx icon indicating copy to clipboard operation
mlx copied to clipboard

Masked gather

Open CC-Yeh opened this issue 1 month ago • 2 comments

It would be great to support boolean-mask indexing, e.g.:

out = values[mask]

to gather all elements where mask == True.

Right now, this requires manual index construction and workarounds (e.g., prefix + scatter_add), which is both verbose and slower than a dedicated masked gather. A built-in op for boolean mask selection would simplify code and improve performance for common use cases where we extract values based on a mask.

CC-Yeh avatar Nov 08 '25 22:11 CC-Yeh

Is this the same with https://github.com/ml-explore/mlx/issues/246?

zcbenz avatar Nov 13 '25 22:11 zcbenz

Yes, I think masked_gather would be a nice way to support #246.

CC-Yeh avatar Nov 14 '25 11:11 CC-Yeh