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

Fix quaternion comparison #8

Merged
merged 24 commits into from
Nov 24, 2017
Merged

Fix quaternion comparison #8

merged 24 commits into from
Nov 24, 2017

Conversation

slava-kerner
Copy link

@slava-kerner slava-kerner commented Nov 16, 2017

  1. Quaternion.log() now returns np.array, and not Quaternion - since log of a quaternion is not defined up to scale, and can be [0, 0, 0, 0].
    it actually resides in lie algebra, not in the lie group.
  2. respectively Quaternion.exp() can now take also np.array, to enable Quaternion.exp(0, 0, 0, 0)

this fixes problems of numerically unstable quaternions (where log(identity)=0)

@coveralls
Copy link

coveralls commented Nov 16, 2017

Coverage Status

Coverage increased (+0.1%) to 90.286% when pulling 4b960ff on fix_quaternion_comparison into 28dba2a on master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 90.286% when pulling 4b960ff on fix_quaternion_comparison into 28dba2a on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 90.286% when pulling 4b960ff on fix_quaternion_comparison into 28dba2a on master.

@coveralls
Copy link

coveralls commented Nov 16, 2017

Coverage Status

Coverage increased (+0.1%) to 90.286% when pulling 75f583c on fix_quaternion_comparison into 28dba2a on master.

3 similar comments
@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 90.286% when pulling 75f583c on fix_quaternion_comparison into 28dba2a on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 90.286% when pulling 75f583c on fix_quaternion_comparison into 28dba2a on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 90.286% when pulling 75f583c on fix_quaternion_comparison into 28dba2a on master.

@coveralls
Copy link

coveralls commented Nov 16, 2017

Coverage Status

Coverage increased (+0.1%) to 90.286% when pulling 0af64dd on fix_quaternion_comparison into 28dba2a on master.

Copy link
Contributor

@astrojuanlu astrojuanlu left a comment

Choose a reason for hiding this comment

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

Just added a couple of general comments - cannot say anything about the mathematical part.

LICENSE.txt Outdated
@@ -0,0 +1 @@
Satellogic SA Copyright 2017. All our code is GPLv3 licensed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

oops spillover, will remove

setup.cfg Outdated
@@ -0,0 +1,2 @@
[metadata]
description-file = README.md
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing newline

Copy link
Author

Choose a reason for hiding this comment

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

oops spillover, is it needed?? @Juanlu001

Copy link
Contributor

Choose a reason for hiding this comment

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

Not mandatory, but when doing $ cat setup.cfg you will see the last line merged with your prompt. Just aesthetic details :)

Copy link
Author

Choose a reason for hiding this comment

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

no, i mean - i added setup.cfg half-accidentally, spillover from some other project.
do we want this file here?

@@ -1,2 +1,2 @@
# https://www.python.org/dev/peps/pep-0440/
__version__ = '0.1.3.dev0'
__version__ = '0.1.3.dev1'
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm sure @matiasg wants to release a stable version sooner than later :)

Copy link
Author

Choose a reason for hiding this comment

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

yep, i think there are 2 more PRs pending, after which 0.1.4?

@astrojuanlu
Copy link
Contributor

astrojuanlu commented Nov 16, 2017 via email

@coveralls
Copy link

coveralls commented Nov 16, 2017

Coverage Status

Coverage increased (+0.1%) to 90.286% when pulling 38495b6 on fix_quaternion_comparison into 28dba2a on master.

@coveralls
Copy link

coveralls commented Nov 21, 2017

Coverage Status

Coverage increased (+1.3%) to 91.429% when pulling 17a258f on fix_quaternion_comparison into 28dba2a on master.

Copy link
Collaborator

@matiasg matiasg left a comment

Choose a reason for hiding this comment

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

I like the whole thing a lot. There are a few things to settle down though (like, for instance, where average method belongs to).


def __add__(self, p):
if not is_quaternion(p):
raise QuaternionError('expected quaternion, got %s' % p)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that the message would be more clear would it be
'expected quaternion, got %s' % type(p)
or even
'expected quaternion, got %s' % p.__class__.__name__

Copy link
Author

@slava-kerner slava-kerner Nov 21, 2017

Choose a reason for hiding this comment

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

fixed

def __add__(self, p):
if not is_quaternion(p):
raise QuaternionError('expected quaternion, got %s' % p)
return self.__class__(self.qr + p.qr, self.qi + p.qi, self.qj + p.qj, self.qk + p.qk)
Copy link
Collaborator

Choose a reason for hiding this comment

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

the sum of two quaternions should be a GeneralQuaternion.
Same thing for __sub__

Notice that with this definition, sum would not commute:

In [13]: p
Out[13]: GeneralQuaternion[ 0.18257419  0.36514837  0.54772256  0.73029674]  # <-- p is actually a Quaternion

In [14]: q
Out[14]: GeneralQuaternion[2 3 4 5]

In [15]: p + q
Out[15]: GeneralQuaternion[ 0.2616049   0.40334909  0.54509328  0.68683747]

In [16]: q + p
Out[16]: GeneralQuaternion[ 2.18257419  3.36514837  4.54772256  5.73029674]

Copy link
Author

@slava-kerner slava-kerner Nov 21, 2017

Choose a reason for hiding this comment

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

fixed



def is_quaternion(q):
return issubclass(type(q), GeneralQuaternion)
Copy link
Collaborator

Choose a reason for hiding this comment

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

is there any reason not to use
isinstance(q, GeneralQuaternion)?
Isinstance seems more natural to me. Anyway, this might just be one of those subjective differences; no need to change it if you prefer this form.

return self.qr * self.qr + self.qi * self.qi + self.qj * self.qj + self.qk * self.qk

def __repr__(self):
return 'GeneralQuaternion{}'.format(self.coordinates)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since now self.coordinates is a np.array, it would be better to convert them to tuple here:
'GeneralQuaternion{}'.format(tuple(self.coordinates))

Copy link
Author

@slava-kerner slava-kerner Nov 21, 2017

Choose a reason for hiding this comment

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

fixed

@@ -12,7 +12,7 @@
setup(
name='satellogic_quaternions',
version=version["__version__"],
author='Matias Graña',
author='Matias Graña, Enrique Toomey, Slava Kerner',
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍
Maybe we have to change the email accordingly.

def inverse(self):
return self.conjugate() * (1 / self._squarenorm())
def __call__(self, p):
return self * p
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is an interesting feature :-) I'm not sure people would use the function syntax for anything else than multiplying by a 3-dimensional vector. Maybe, I'd add an assert isinstance(p, Iterable) and len(p) == 3, or something like that, just to prevent an unintended incorrect use.

Copy link
Author

@slava-kerner slava-kerner Nov 21, 2017

Choose a reason for hiding this comment

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

fixed


def is_unitary(self):
return abs(self._squarenorm() - 1) < self.tolerance
j, k, l = imag / imag_norm * np.arctan2(imag_norm, self.qr / norm)
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not i, j, k instead of j, k, l?

Copy link
Author

@slava-kerner slava-kerner Nov 21, 2017

Choose a reason for hiding this comment

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

fixed

from quaternions.general_quaternion import GeneralQuaternion, QuaternionError, DEFAULT_TOLERANCE


ANY_QUATERNION = strategies.lists(elements=strategies.floats(min_value=-5, max_value=5), min_size=4, max_size=4)
Copy link
Collaborator

Choose a reason for hiding this comment

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

awesome! :-)

assert q + q == 2 * q == q * 2
assert q - q == GeneralQuaternion.zero()
assert q * GeneralQuaternion.zero() == q * 0 == GeneralQuaternion.zero()
assert q * GeneralQuaternion.unit() == q * 1 == q
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 add a line with the multiplications in the other order:

assert GeneralQuaternion.unit() * q == 1 * q == q

Copy link
Author

@slava-kerner slava-kerner Nov 21, 2017

Choose a reason for hiding this comment

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

fixed

@given(ANY_QUATERNION)
def test_conjugate(self, arr):
q = GeneralQuaternion(*arr)
assert (q + q.conjugate()).is_real()
Copy link
Collaborator

@matiasg matiasg Nov 21, 2017

Choose a reason for hiding this comment

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

fixed

Copy link
Author

Choose a reason for hiding this comment

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

yes

Copy link
Collaborator

Choose a reason for hiding this comment

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

😮 github allows to edit other's comments.
Anyway, it's fixed 😉

@coveralls
Copy link

Coverage Status

Coverage increased (+5.7%) to 95.89% when pulling ff0e95e on fix_quaternion_comparison into 28dba2a on master.

1 similar comment
@coveralls
Copy link

coveralls commented Nov 22, 2017

Coverage Status

Coverage increased (+5.7%) to 95.89% when pulling ff0e95e on fix_quaternion_comparison into 28dba2a on master.

@coveralls
Copy link

coveralls commented Nov 22, 2017

Coverage Status

Coverage increased (+5.7%) to 95.89% when pulling 15329d0 on fix_quaternion_comparison into 28dba2a on master.

@coveralls
Copy link

coveralls commented Nov 22, 2017

Coverage Status

Coverage increased (+5.7%) to 95.89% when pulling 932d7e9 on fix_quaternion_comparison into 28dba2a on master.

@matiasg
Copy link
Collaborator

matiasg commented Nov 24, 2017

👍

@matiasg matiasg merged commit 8f57a95 into master Nov 24, 2017
@matiasg matiasg deleted the fix_quaternion_comparison branch November 24, 2017 19:48
matiasg added a commit that referenced this pull request Jul 27, 2020
# This is the 1st commit message:

pin coveralls version

# This is the commit message #2:

rever change of pytest-coverage. Pin python-coverage

# This is the commit message #3:

just as a test, remove coveralls

# This is the commit message #4:

remove also cov from script 🤦

# This is the commit message #5:

pin pytest version

# This is the commit message #6:

pin hypothesis version

# This is the commit message #7:

pin hypothesis to 3.55.1 now

# This is the commit message #8:

do not install pytest-coverage

# This is the commit message #9:

pin pytest-coverage

# This is the commit message #10:

install pinned coverage, do not install pytest-coverage :'(

# This is the commit message #11:

pin attr

# This is the commit message #12:

attr is attrs

# This is the commit message #13:

travis, please tell me attr version

# This is the commit message #14:

go back to original setup.py

# This is the commit message #15:

exclude coveralls from 3.4 & 3.5. Try 1

# This is the commit message #16:

use [] instead of test

# This is the commit message #17:

install pytest 5.4.3

# This is the commit message #18:

travis tell me something

# This is the commit message #19:

please do tell

# This is the commit message #20:

ooohhh?

# This is the commit message #21:

oh 2

# This is the commit message #22:

oh 3

# This is the commit message #23:

oh 4

# This is the commit message #24:

oh 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants