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