From d02617c9616e7fdc309b80500fb70f39a1b9282f Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Tue, 15 Sep 2020 13:09:24 -0400 Subject: [PATCH 1/2] fixed normalization of multidimensional axes (from_Rodrigues, from_axis_angle) --- python/damask/_rotation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/damask/_rotation.py b/python/damask/_rotation.py index ac7b3ace8..c023984e6 100644 --- a/python/damask/_rotation.py +++ b/python/damask/_rotation.py @@ -434,7 +434,7 @@ class Rotation: if P == 1: ax[...,0:3] *= -1 if degrees: ax[..., 3] = np.radians(ax[...,3]) - if normalize: ax[...,0:3] /= np.linalg.norm(ax[...,0:3],axis=-1) + if normalize: ax[...,0:3] /= np.linalg.norm(ax[...,0:3],axis=-1,keepdims=True) if np.any(ax[...,3] < 0.0) or np.any(ax[...,3] > np.pi): raise ValueError('Axis angle rotation angle outside of [0..π].') if not np.all(np.isclose(np.linalg.norm(ax[...,0:3],axis=-1), 1.0)): @@ -516,7 +516,7 @@ class Rotation: raise ValueError('P ∉ {-1,1}') if P == 1: ro[...,0:3] *= -1 - if normalize: ro[...,0:3] /= np.linalg.norm(ro[...,0:3],axis=-1) + if normalize: ro[...,0:3] /= np.linalg.norm(ro[...,0:3],axis=-1,keepdims=True) if np.any(ro[...,3] < 0.0): raise ValueError('Rodrigues vector rotation angle not positive.') if not np.all(np.isclose(np.linalg.norm(ro[...,0:3],axis=-1), 1.0)): From 9e93e8b7102986b1bdd75a5d5a59f925727b6ce8 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 15 Sep 2020 19:59:03 +0200 Subject: [PATCH 2/2] test for last commit --- python/tests/test_Rotation.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/python/tests/test_Rotation.py b/python/tests/test_Rotation.py index 3ed1f27c6..1696ef247 100644 --- a/python/tests/test_Rotation.py +++ b/python/tests/test_Rotation.py @@ -686,6 +686,15 @@ class TestRotation: print(u,c) assert np.allclose(single(u),c) and np.allclose(single(u),vectorized(u)) + @pytest.mark.parametrize('func',[Rotation.from_axis_angle]) + def test_normalization_vectorization(self,func): + """Check vectorized implementation normalization.""" + vec = np.random.rand(5,4) + ori = func(vec,normalize=True) + for v,o in zip(vec,ori): + assert np.allclose(func(v,normalize=True).as_quaternion(),o.as_quaternion()) + + @pytest.mark.parametrize('degrees',[True,False]) def test_Eulers(self,set_of_rotations,degrees): for rot in set_of_rotations: