feat: add applyAlongAxis to reduce a matrix along a chosen dimension - #214
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #214 +/- ##
==========================================
+ Coverage 68.58% 68.88% +0.30%
==========================================
Files 49 49
Lines 5847 5904 +57
Branches 1042 1060 +18
==========================================
+ Hits 4010 4067 +57
Misses 1824 1824
Partials 13 13 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
targos
reviewed
Aug 5, 2026
targos
left a comment
Member
There was a problem hiding this comment.
Code LGTM. I made a few changes to the API so it's more generic and closer to the existing axis reducer methods.
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.
Closes #154.
Summary
ml-matrixships fixed reductions along a dimension, such assum,product,mean, with no way to supply a custom one. The linked issue reports having to copy a small helper between projects to collapse each row into a single value.This adds
applyAlongAxis(callback, by)onAbstractMatrix, using the signature proposed in the issue thread:Behaviour
by === 'row'calls the callback once per row, receiving that row as a plain array plus its index. The result is a column vector of sizerows x 1.by === 'column'calls the callback once per column. The result is a row vector of size1 x columns.apply.callback must be a function. An unknown dimension throwsinvalid option: <value>, matchingsum,product,mean.Matrix, including when the receiver is a view, aSymmetricMatrix, aDistanceMatrix.Defining it on
AbstractMatrixmeans every matrix flavour picks it up.Example
The typing in
matrix.d.tsis updated alongside the implementation. The README gains a short example under the existing examples section.