Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flake8 + test fixes #20

Merged
merged 4 commits into from
Apr 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion quaternions/general_quaternion.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ def normalized(self):
return self / self.norm()

def euclidean_distance(self, other):
""" Returns the euclidean distance between two quaternions. Note: differs from unitary quaternions distance. """
"""
Returns the euclidean distance between two quaternions.
Note: differs from unitary quaternions distance.
"""
return (self - other).norm()

def is_unitary(self, tolerance=DEFAULT_TOLERANCE):
Expand Down
10 changes: 7 additions & 3 deletions quaternions/quaternion.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import numbers

from quaternions.utils import (covariance_matrix_from_angles, sigma_lerner, xi_matrix)
from quaternions.general_quaternion import GeneralQuaternion, QuaternionError, DEFAULT_TOLERANCE, exp
from quaternions.general_quaternion import (
GeneralQuaternion, QuaternionError, DEFAULT_TOLERANCE, exp
)


class Quaternion(GeneralQuaternion):
Expand Down Expand Up @@ -42,7 +44,9 @@ def __call__(self, p):
try:
return self * p
except Exception as e:
raise QuaternionError('expected list of 3 elements, got %s, caused error: %s' % (p.__class__.__name__, e))
raise QuaternionError(
'expected list of 3 elements, got %s, caused error: %s' %
(p.__class__.__name__, e))

def is_equal(self, other, tolerance=DEFAULT_TOLERANCE):
""" compares as quaternions, i.e. up to sign. """
Expand Down Expand Up @@ -226,7 +230,7 @@ def from_qmethod(source, target, probabilities=None):
K[1:4, 0] = [i, j, k]
K[1:4, 1:4] = S - sigma * np.identity(3)
return Quaternion._first_eigenvector(K)

@staticmethod
def average_and_std_naive(*quaternions, weights=None):
"""
Expand Down
7 changes: 4 additions & 3 deletions tests/test_quaternion.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from hypothesis import given, assume, strategies
from hypothesis import given, assume, strategies, example
import numpy as np
import pytest
import os
Expand Down Expand Up @@ -137,6 +137,7 @@ def test_basis(self, arr):
assert np.array_equal([b1, b2, b3], q.matrix)

@given(ANY_ROTATION_VECTOR)
@example([3.7500000000000733, 0.0, 3.5030739510277804e-05])
def test_from_ra_dec_roll(self, arr):
xyz = np.deg2rad(arr)
c3, c2, c1 = np.cos(xyz)
Expand All @@ -147,7 +148,7 @@ def test_from_ra_dec_roll(self, arr):
[s1 * s3 - c1 * c3 * s2, c3 * s1 + c1 * s2 * s3, c1 * c2] # noqa
]))

assert Quaternion.from_ra_dec_roll(*arr) == Quaternion.from_matrix(expected)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to explicitly add the @example you wrote in the issue, as this will clarify why we need this tolerance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

assert Quaternion.from_ra_dec_roll(*arr).is_equal(Quaternion.from_matrix(expected), tolerance=5e-8)

@given(ANY_QUATERNION)
def test_ra_dec_roll(self, arr):
Expand Down Expand Up @@ -301,4 +302,4 @@ def test_average_and_covariance(self):
* np.sqrt(len(quat_diff_matlab_quats)-1)

assert abs(sigma_lerner_in_deg - sigma_lerner_out_deg ) \
< self.tolerance_deg
< self.tolerance_deg