Skip to content

Dedupe all-axes boilerplate in ops.cpp with all_axes() helper - #4394

Closed
Adityaj0 wants to merge 1 commit into
ml-explore:mainfrom
Adityaj0:dedupe-all-axes-reduce-helper
Closed

Dedupe all-axes boilerplate in ops.cpp with all_axes() helper#4394
Adityaj0 wants to merge 1 commit into
ml-explore:mainfrom
Adityaj0:dedupe-all-axes-reduce-helper

Conversation

@Adityaj0

Copy link
Copy Markdown
Contributor

Rebase of #4290 on latest main (that PR could not be reopened after the branch was rebased — GitHub blocks reopening once a PR's branch has been force-pushed since it was closed).

Fourteen no-axes overloads (flip, all, any, sum, count_nonzero, mean, median, var, std, prod, max, min, logsumexp, softmax) each repeated the same std::iota-based boilerplate to build the "all axes" list before delegating to their axes-taking overload.

Extracted a shared all_axes(int ndim) helper into the existing anonymous namespace alongside compute_reduce_shape, and collapsed each call site to a one-liner. Net diff: 21 insertions / 42 deletions, single file (mlx/ops.cpp). Left pad's default-axes logic and the argmin/argmax keepdims expansion untouched since they build a different range.

Behavior-preserving — verified with the full C++ test suite (ops_tests.cpp).

Fourteen reduce/elementwise ops (flip, all, any, sum, count_nonzero,
mean, median, var, std, prod, max, min, logsumexp, softmax) each
repeated the same std::iota block to build a 0..ndim-1 axis list for
their no-axes overload. Factor this into a single all_axes(ndim)
helper alongside the existing compute_reduce_shape helper.
@nastya236

Copy link
Copy Markdown
Collaborator

I believe this is a duplicate of #4395. Do you mind closing one of them if that’s the case?

@nastya236 nastya236 added low priority await response This pull request is waiting for response from the author. labels Aug 25, 2026
@nastya236

Copy link
Copy Markdown
Collaborator

#4395

@nastya236 nastya236 closed this Aug 25, 2026
@Adityaj0

Copy link
Copy Markdown
Contributor Author

#4395

This should not be closed it was an existing issue waiting for rebase.

@nastya236

Copy link
Copy Markdown
Collaborator

I am not following. #4395 and #4394 are identical pull requests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

await response This pull request is waiting for response from the author. low priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants