Skip to content

Commit

Permalink
Merge branch 'master' into improve_coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasg committed Apr 28, 2018
2 parents f90b648 + a2e74cf commit 3d1d7b4
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 13 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ python:
- "3.6"
- "3.6-dev"
- "nightly" # currently points to 3.7-dev

matrix:
allow_failures:
- python: "nightly"

install:
- "pip install --editable .[dev]"
- "pip install -r requirements-test.txt"
- "pip install python-coveralls"
script:
- "pytest -v --cov-report= --cov=quaternions tests/"
Expand Down
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
)

import warnings

Expand Down Expand Up @@ -44,7 +46,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 @@ -230,7 +234,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
4 changes: 0 additions & 4 deletions requirements-test.txt

This file was deleted.

7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@
'numpy',
],
extras_require={
"dev": [
"hypothesis",
'dev': [
'flake8 >= 2.5.4',
'hypothesis',
'pytest',
'pytest-coverage',
]
}
)
5 changes: 3 additions & 2 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

0 comments on commit 3d1d7b4

Please sign in to comment.