Repository navigation
Take part of a matrix by range (#443) - #683
Merged
Happypig375 merged 1 commit intoAug 4, 2026
Merged
Conversation
a[1.., ..] is every row of a matrix but the first, a[..2, 1..3] the first two rows of its second and third columns, and a[^1.., ^1..] its bottom right entry. The result is an ordinary matrix sharing nothing with the one it came from. Both extents have to be written out, which is what the issue's own discussion asks for. A matrix indexed by one number gives a row while a vector indexed by one number gives an element, so a single range would have to mean one thing here and the other there; there is no one-range indexer to write, so the question cannot come up. An empty range is refused rather than answered with a matrix of no rows, since there is no such matrix; a range reaching past the matrix throws from the range itself. Ten tests, 3890 in all, 127 F#.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #683 +/- ##
==========================================
- Coverage 80.99% 80.14% -0.85%
==========================================
Files 155 156 +1
Lines 13687 12648 -1039
Branches 1957 2064 +107
==========================================
- Hits 11086 10137 -949
+ Misses 1990 1914 -76
+ Partials 611 597 -14 ☔ 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.
Closes #443.
The result is an ordinary matrix sharing nothing with the one it came from, so it transposes, multiplies and compares like any other.
Both extents have to be written out
@Happypig375 asked on the issue for
a[1.., ..]rather thana[1..], and that is what this does — there is no one-range indexer, so the shorter form does not compile.The reason it would be ambiguous is already in the type:
this[int i]gives the i-th row of a matrix but the i-th element of a vector, since a vector is a matrix of one column. A single range would have to inherit that and mean one thing for one shape and another for the other. With both extents written out, a vector is cut by its first extent like anything else andColumn[1.., ..]drops its first element.Edges
An empty range is refused with
InvalidMatrixOperationExceptionrather than answered with a matrix of no rows, because there is no such matrix. A range reaching past the matrix throwsArgumentOutOfRangeExceptionfromRange.GetOffsetAndLengthitself, so the message names the real problem.System.Rangecompiles on bothnet7.0andnetstandard2.0here, so the API is the same on both — I checked before writing it rather than assuming.Verification
Ten tests covering each form above, the whole-matrix case, a vector, symbolic entries carried over untouched, and both refusals. 3890 unit tests and 127 F# tests on both target frameworks, none failing.
These tests do not fail before the change — they do not compile, since the indexer they call does not exist. That is the only "before" a new API has.