Skip to content

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

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#4290
Adityaj0 wants to merge 1 commit into
ml-explore:mainfrom
Adityaj0:dedupe-all-axes-reduce-helper

Conversation

@Adityaj0

Copy link
Copy Markdown
Contributor

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, notably test flip and test reduction ops): 263 test cases, 3578 assertions, all passing. pre-commit run (clang-format) also passed clean.

Closes #4289 (originally filed against this repo by mistake, refiled at Adityaj0#1)

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.
@zcbenz

zcbenz commented Aug 16, 2026

Copy link
Copy Markdown
Member

Can you rebase on latest main?

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

zcbenz commented Aug 22, 2026

Copy link
Copy Markdown
Member

@Adityaj0 Can you rebase on latest main?

@Adityaj0

Copy link
Copy Markdown
Contributor Author

Rebased on latest main. GitHub won't let me reopen this PR since the branch was force-pushed after it closed, so continuing here: #4394

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.

Duplicated all-axes boilerplate across reduction/elementwise ops in ops.cpp

2 participants