From 98723cb0ed5155d83bf6e2605e35466d575e40bd Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 3 Jan 2021 15:50:15 +0100 Subject: [PATCH] need to handle special case of Re() = 0 ensuring that the real part is positive seems to be a good idea on first sight, but it would be easier to simply acknowledge that qu = -qu --- python/damask/_rotation.py | 4 +++- python/tests/test_Rotation.py | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/python/damask/_rotation.py b/python/damask/_rotation.py index 492ca8d2d..4b03e8f56 100644 --- a/python/damask/_rotation.py +++ b/python/damask/_rotation.py @@ -105,8 +105,10 @@ class Rotation: Rotation to check for equality. """ + ambiguous = np.isclose(self.quaternion[...,0],0) return np.prod(self.shape,dtype=int) == np.prod(other.shape,dtype=int) \ - and np.allclose(self.quaternion,other.quaternion) + and ( np.allclose(self.quaternion,other.quaternion) \ + or np.allclose(self.quaternion[ambiguous],-1*other.quaternion[ambiguous])) @property diff --git a/python/tests/test_Rotation.py b/python/tests/test_Rotation.py index f8f1a3da7..bc6614fb9 100644 --- a/python/tests/test_Rotation.py +++ b/python/tests/test_Rotation.py @@ -786,6 +786,12 @@ class TestRotation: def test_equal(self): assert Rotation.from_random(rng_seed=1) == Rotation.from_random(rng_seed=1) + def test_equal_ambiguous(self): + qu = np.random.rand(10,4) + qu[:,0] = 0. + qu/=np.linalg.norm(qu,axis=1,keepdims=True) + assert Rotation(qu) == Rotation(-qu) + def test_inversion(self): r = Rotation.from_random() assert r == ~~r