From beb58b76f2740364b502e4e13fbc741d0fb524d4 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 6 Dec 2023 22:07:57 +0100 Subject: [PATCH 1/3] correctly handling ambiguity if Phi approx pi --- python/tests/test_Rotation.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/python/tests/test_Rotation.py b/python/tests/test_Rotation.py index 5a2d91a6e..cbcd06c3d 100644 --- a/python/tests/test_Rotation.py +++ b/python/tests/test_Rotation.py @@ -537,9 +537,12 @@ class TestRotation: u = np.array([np.pi*2,np.pi,np.pi*2]) ok = np.allclose(m,o,atol=atol) ok |= np.allclose(np.where(np.isclose(m,u),m-u,m),np.where(np.isclose(o,u),o-u,o),atol=atol) - if np.isclose(m[1],0.0,atol=atol) or np.isclose(m[1],np.pi,atol=atol): + if np.isclose(m[1],0.0,atol=atol): sum_phi = np.unwrap([m[0]+m[2],o[0]+o[2]]) - ok |= np.isclose(sum_phi[0],sum_phi[1],atol=atol) + ok |= np.isclose(sum_phi[0],sum_phi[1],atol=atol) and np.isclose(o[1],0.0,atol=atol) + if np.isclose(m[1],np.pi,atol=atol): + delta_phi = np.unwrap([m[0]-m[2],o[0]-o[2]]) + ok |= np.isclose(delta_phi[0],delta_phi[1],atol=atol) and np.isclose(o[1],np.pi,atol=atol) assert ok and (np.zeros(3)-1.e-9 <= o).all() \ and (o <= np.array([np.pi*2.,np.pi,np.pi*2.])+1.e-9).all(), f'{m},{o},{rot.as_quaternion()}' From efc76f1f195f1124fbc30a40087d7d77fee76db2 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Sat, 9 Dec 2023 12:03:05 -0500 Subject: [PATCH 2/3] shortened code --- python/tests/test_Rotation.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/python/tests/test_Rotation.py b/python/tests/test_Rotation.py index cbcd06c3d..7b079d30a 100644 --- a/python/tests/test_Rotation.py +++ b/python/tests/test_Rotation.py @@ -534,17 +534,15 @@ class TestRotation: for rot in set_of_rotations: m = rot.as_Euler_angles() o = backward(forward(m)) - u = np.array([np.pi*2,np.pi,np.pi*2]) - ok = np.allclose(m,o,atol=atol) + u = np.pi*np.array([2.,1.,2.]) + ok = np.allclose(m,o,atol=atol) ok |= np.allclose(np.where(np.isclose(m,u),m-u,m),np.where(np.isclose(o,u),o-u,o),atol=atol) - if np.isclose(m[1],0.0,atol=atol): - sum_phi = np.unwrap([m[0]+m[2],o[0]+o[2]]) - ok |= np.isclose(sum_phi[0],sum_phi[1],atol=atol) and np.isclose(o[1],0.0,atol=atol) - if np.isclose(m[1],np.pi,atol=atol): - delta_phi = np.unwrap([m[0]-m[2],o[0]-o[2]]) - ok |= np.isclose(delta_phi[0],delta_phi[1],atol=atol) and np.isclose(o[1],np.pi,atol=atol) + if np.allclose([m[1],o[1]],0.0,atol=atol): + ok |= np.isclose(*np.unwrap([m[0]+m[2],o[0]+o[2]]),atol=atol) + if np.allclose([m[1],o[1]],np.pi,atol=atol): + ok |= np.isclose(*np.unwrap([m[0]-m[2],o[0]-o[2]]),atol=atol) assert ok and (np.zeros(3)-1.e-9 <= o).all() \ - and (o <= np.array([np.pi*2.,np.pi,np.pi*2.])+1.e-9).all(), f'{m},{o},{rot.as_quaternion()}' + and ( o <= u+1.e-9).all(), f'{m},{o},{rot.as_quaternion()}' @pytest.mark.parametrize('forward,backward',[(Rotation._ax2qu,Rotation._qu2ax), (Rotation._ax2om,Rotation._om2ax), From afa80bab688cdc9644bb69a4902b44fd3150eae7 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Sat, 9 Dec 2023 12:03:24 -0500 Subject: [PATCH 3/3] use numpy intrinsics --- python/tests/conftest.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/python/tests/conftest.py b/python/tests/conftest.py index dc4b44a6a..8ff000ca3 100644 --- a/python/tests/conftest.py +++ b/python/tests/conftest.py @@ -150,6 +150,7 @@ def set_of_quaternions(): specials_scatter /= np.linalg.norm(specials_scatter,axis=1).reshape(-1,1) specials_scatter[specials_scatter[:,0]<0]*=-1 - return np.array([s for s in specials] + \ - [s for s in specials_scatter] + \ - [s for s in random_quaternions(n-2*len(specials))]) + return np.vstack((specials, + specials_scatter, + random_quaternions(n-2*len(specials)), + ))