fix: add exception in Quaternion.average#35
Open
MarcoMiretti wants to merge 1 commit intosatellogic:masterfrom
Open
fix: add exception in Quaternion.average#35MarcoMiretti wants to merge 1 commit intosatellogic:masterfrom
MarcoMiretti wants to merge 1 commit intosatellogic:masterfrom
Conversation
matiasg
approved these changes
Sep 7, 2020
Collaborator
matiasg
left a comment
There was a problem hiding this comment.
Nice!
Just one comment on the test, but +1 from me.
tests/test_quaternion.py
Outdated
| self.fail('Expected QuaternionError exception to be raised') | ||
| except QuaternionError: | ||
| pass | ||
| except np.linalg.LinAlgError: |
Collaborator
There was a problem hiding this comment.
Why this exception in particular?
Could it be just except Exception?
Author
There was a problem hiding this comment.
Yes, i guess that's better.
Just to explain why i met this particular exception:
np.linalg.LinAlgError is what happens when we try to np.linalg.eigh(matrix) for a matrix of rank less than two.
In the case of an empty quaternion list gives us:
b = np.array([])
weights = np.array([])then:
m = 0.0So we end up calling:
cls._first_eigenvector(0.0)which leads to:
np.linalg.eigh(0.0)
--> np.linalg.LinAlgErrorIn this test, except Exception is much better, since for example, _first_eigenvector could change in the future, checking the rank of its input and raising exceptions if they aren't met. That would break this test unnecessarily.
When trying to average an empty list of quaternions, rise a QuaternionError, explaining that it takes at least one quaternion to calculate the average.
e219864 to
6a6fae3
Compare
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.
When trying to average an empty list of quaternions, rise a
QuaternionError, explaining that it takes at least one quaternion tocalculate the average.