Repository navigation
fix: stop rowEchelon mutating its input matrix - #2036
Open
Aditya2375 wants to merge 2 commits into
Open
Aditya2375 wants to merge 2 commits into
Aditya2375 wants to merge 2 commits into
Conversation
Change result assignment to create a copy of the matrix.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2036 +/- ##
=======================================
Coverage 85.91% 85.91%
=======================================
Files 379 379
Lines 19778 19778
Branches 3016 3017 +1
=======================================
Hits 16993 16993
Misses 2785 2785 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Describe your change:
What:
rowEchelon()mutates the caller's matrix in place.resultaliases the input (let result = matrix) and every row operation (pivot select, scalar multiply, row subtract) writes through it.Why: a reduction function should not destroy its argument.
rowEchelon([[1,2,3],[4,5,6],[7,8,10]])returns the correct row echelon form, but the caller's original matrix is gone afterwards - the returned value is the same object as the input.Change: work on a copy (
matrix.map((row) => [...row])) and add a regression test asserting the input matrix is unchanged and the result is a different object. The new test fails on the current implementation; all existing RowEchelon tests still pass.Checklist:
Fixes: #{$ISSUE_NO}.