-
Notifications
You must be signed in to change notification settings - Fork 6
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
Conversation
2) Quaternion.exp() takes np.array
2 similar comments
…assignment target"
…assignment target"
3 similar comments
There was a problem hiding this 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed: https://github.com/satellogic/quaternions/blob/master/LICENSE
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing newline
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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?
Oh, in this case I'd remove it - not sure what's the effect of that line.
…On Nov 16, 2017 11:01, "slava-kerner" ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In setup.cfg
<#8 (comment)>:
> @@ -0,0 +1,2 @@
+[metadata]
+description-file = README.md
no, i mean - i added setup.cfg half-accidentally, spillover from some
other project.
do we want this file here?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#8 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AATUZbOdB1zNc87FX3n9E6B3lsX7yHlJks5s3AfogaJpZM4QgD_W>
.
|
There was a problem hiding this 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).
quaternions/general_quaternion.py
Outdated
|
||
def __add__(self, p): | ||
if not is_quaternion(p): | ||
raise QuaternionError('expected quaternion, got %s' % p) |
There was a problem hiding this comment.
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__
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
quaternions/general_quaternion.py
Outdated
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) |
There was a problem hiding this comment.
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]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
quaternions/general_quaternion.py
Outdated
|
||
|
||
def is_quaternion(q): | ||
return issubclass(type(q), GeneralQuaternion) |
There was a problem hiding this comment.
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.
quaternions/general_quaternion.py
Outdated
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) |
There was a problem hiding this comment.
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))
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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.
quaternions/quaternions.py
Outdated
def inverse(self): | ||
return self.conjugate() * (1 / self._squarenorm()) | ||
def __call__(self, p): | ||
return self * p |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
quaternions/quaternions.py
Outdated
|
||
def is_unitary(self): | ||
return abs(self._squarenorm() - 1) < self.tolerance | ||
j, k, l = imag / imag_norm * np.arctan2(imag_norm, self.qr / norm) |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
tests/test_general_quaternion.py
Outdated
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
There was a problem hiding this comment.
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 😉
1 similar comment
👍 |
# 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
it actually resides in lie algebra, not in the lie group.
this fixes problems of numerically unstable quaternions (where log(identity)=0)