Replace array_search with floating-point filter in Eigenvector::eigenvectors
#473
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.
Addresses the error found in #472
When given eigenvalues containing duplicates, the
Eigenvector::eigenvectors
method fails in cases where the$eigenvalues
array is made up of floats. The culprit is the floating point comparison inarray_search
when checking for orthogonal eigenvectors. Even in the case it does find a match, it can still fail if the match is at index 0 because the body of the method is guarded by a check for!$key
. If$key = 0
, php evaluates!0
to true because 0 is falsey, so it can still fail to return the correct eigenvectors.We can instead loop through the found solutions, checking if the current eigenvalue has been solved with
Arithmetic::almostEqual
, and then explicitly check if$key === false
.I noticed that there aren't any test cases in the EigenvectorTest that would have caught this - should I add a few?