fix(median): handle empty axes in mlx_median_axes - #133
Open
aki-xavier wants to merge 1 commit into
Open
Conversation
Passing axes=NULL/axes_num=0 to mlx_median_axes builds an empty axes vector that flows into the axes overload of mlx::core::median. That overload transposes all axes to the back and calls flatten(start == ndim), which is rejected by the assert '[flatten] start_axis must be less than or equal to end_axis'. Route the no-axis case (axes_num == 0) to the full-reduce overload, mirroring the dedicated mlx_median entry point, so reducing over all dimensions works. Fixes ml-explore#128.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
mlx_median_axes(res, a, NULL, 0, keepdims, s)— the "reduce over all dimensions" spelling — builds an empty axes vector that flows into the axes overload ofmlx::core::median. That overload moves all axes to the back and callsflatten(start_axis == ndim), which is rejected by the assertion:This makes the all-axes median unusable through the
_axesentry point. The dedicated no-axis entry pointmlx_medianalready routes to the full-reduce overload and works; only the_axespath is broken.Reproduction
Fix
When
axes_num == 0, route to the full-reduce overloadmlx::core::median(a, keepdims, s)directly, mirroring the dedicatedmlx_medianentry point. The normalaxes_num > 0path is unchanged.Verification
Built
mlxc(CPU backend) and ran a small program against it:mlx_median(a, keepdims=false)rc=0,2.5rc=0,2.5mlx_median_axes(a, NULL, 0, ...)rc=1, flatten assertrc=0,2.5mlx_median_axes(a, axis=0, ...)rc=0rc=0Fixes #128.