From 3c3324fd98eb25172b47e9cb2c0e7f0c4afd177e Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Sat, 2 Mar 2024 15:43:04 -0500 Subject: [PATCH 1/2] prevent rightmost dimension of object from blending with rotation array --- python/damask/_rotation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/damask/_rotation.py b/python/damask/_rotation.py index c955b2da0..003e9504c 100644 --- a/python/damask/_rotation.py +++ b/python/damask/_rotation.py @@ -442,7 +442,7 @@ def __matmul__(self, """ if isinstance(other, np.ndarray): - obs = util.shapeblender(self.shape,other.shape)[len(self.shape):] + obs = (util.shapeblender(self.shape,other.shape[:-1])+other.shape[-1:])[len(self.shape):] for l in [4,2,1]: if obs[-l:] == l*(3,): bs = util.shapeblender(self.shape,other.shape[:-l],False) From c0c754a03fe7e12b420fd1d7fceb45652cc2cb89 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sun, 3 Mar 2024 11:39:04 +0100 Subject: [PATCH 2/2] test broadcasting abilities --- python/tests/test_Rotation.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/python/tests/test_Rotation.py b/python/tests/test_Rotation.py index 7b079d30a..527dbf475 100644 --- a/python/tests/test_Rotation.py +++ b/python/tests/test_Rotation.py @@ -990,6 +990,7 @@ def test_broadcastcomposition(self,shape): (Rotation.from_axis_angle, np.array([1,0,0,4])), (Rotation.from_axis_angle, np.array([1,1,0,1])), (Rotation.from_matrix, np.random.rand(3,3)), + (Rotation.from_matrix, np.array([[2,0,0],[0,2,0],[0,1,0]])), (Rotation.from_matrix, np.array([[1,1,0],[1,2,0],[0,0,1]])), (Rotation.from_Rodrigues_vector, np.array([1,0,0,-1])), (Rotation.from_Rodrigues_vector, np.array([1,1,0,1])), @@ -1128,10 +1129,13 @@ def test_invariant(self): R = Rotation.from_random() assert (R/R).isclose(R*R**(-1)) and (R/R).isclose(Rotation()) - @pytest.mark.parametrize('item',[np.ones(3),np.ones((3,3)), np.ones((3,3,3,3))]) - def test_apply(self,item): - r = Rotation.from_random() - assert (r.apply(item) == r@item).all() + @pytest.mark.parametrize('shape',[None,2,(2,3),(2,2),(2,3,3,3)]) + @pytest.mark.parametrize('item',[np.random.rand(3),np.random.rand(3,3), np.random.rand(3,3,3,3)]) + def test_apply(self,item,shape): + r = Rotation.from_random(shape) + i = r*~r + applied = i.apply(item) + assert np.allclose(np.broadcast_to(item,applied.shape),applied) @pytest.mark.parametrize('angle',[10,20,30,40,50,60,70,80,90,100,120]) def test_average(self,angle):