Skip to content

Commit

Permalink
Merge pull request #20 from AmitAronovitch/fixes
Browse files Browse the repository at this point in the history
flake8 + test fixes
  • Loading branch information
matiasg committed Apr 9, 2018
2 parents ffa3fdf + 5aa3b03 commit a2e74cf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
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)
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

0 comments on commit a2e74cf

Please sign in to comment.