Fix 256: Makes instantiating DenseMatrix and others fallible #258
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.
Fixes issue 256
Several new tests were added to the
src/linalg/basic/matrix.rs
module.All tests pass.
Fixes #
Checklist
Current behaviour
DenseMatrix
relies on the user to properly input the dimensions of the matrix. In the event a mistake is made, the results will either be wrong, or generate an "index out of bounds" error.New expected behaviour
Update the constructors for DenseMatrix. Set return value to
Result<DenseMatrix, Failed>
to reflect the fallible nature of the construction. This is true because the input relies on user input to align with the data provided. In other words, there is no way to infer and/or correct the user input when the implied matrix shape does not align with the data.Change logs
Clearly a breaking change. However, this is a critically important change. There is no way around it. Before the change, it's possible to create references to invalid memory. This update leverages the current error generating infrastructure. In the event the user input is nonsensical (introduces a contradiction) given the actual data, a
Failed::InputError
is returned.DenseMatrix, DenseMatrixView, DenseMatrixMutView, new and from_2d_array methods now validate the input and return a fallible result.
For future use, added a
Failed::InvalidState
to the enum. This may be useful in the development branch to safely assert and otherwise flag when critical to "be in" a valid state.src/linalg/basic/matrix.rs was the core change. All of the tests, throughout the package were updated to reflect the new fallible construction. This was prolific, but simple: tagging
.unwrap()
to the constructions used in the tests.