feat: add concat to join two matrices along a chosen dimension - #215
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #215 +/- ##
==========================================
+ Coverage 68.58% 68.73% +0.15%
==========================================
Files 49 49
Lines 5847 5876 +29
Branches 1042 1050 +8
==========================================
+ Hits 4010 4039 +29
Misses 1824 1824
Partials 13 13 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
targos
approved these changes
Aug 5, 2026
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 #54.
Closes #161.
Summary
The library has no way to join two matrices. Both linked issues ask for one, #161 pointing at the numpy
stack,hstack,vstackequivalents. The maintainer reply on #54 proposedmatrix1.concat(matrix2)returning a new matrix, which is the shape implemented here.API
by === 'row', the default, stacks the two matrices vertically. Both operands need the same number of columns. The result hasthis.rows + other.rowsrows.by === 'column'stacks them side by side. Both operands need the same number of rows. The result hasthis.columns + other.columnscolumns.otherpasses throughMatrix.checkMatrix, meaning a plain 2D array is accepted.Matrix, including when the receiver is a view, aSymmetricMatrix, aDistanceMatrix.RangeErrornaming the dimension that has to match. An unknown dimension throwsinvalid option: <value>, matchingsum,product,mean.Values are copied once into a preallocated result through
setSubMatrix, leaving a single allocation per call. Matrices with a zero dimension are handled, which keeps the result predictable when one side carries no data.Example
Chaining covers more than two operands, as in
a.concat(b).concat(c).The typing in
matrix.d.tsis updated alongside the implementation. The README gains a short example under the existing examples section.