Skip to content

Commit 309937b

Browse files
committed
Merge branch '387-rotation-clash-when-last-dimension-is-three' into 'development'
prevent rightmost dimension of object from blending with rotation array Closes #387 See merge request damask/DAMASK!915
2 parents 0b1629a + c0c754a commit 309937b

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

python/damask/_rotation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ def __matmul__(self,
442442
443443
"""
444444
if isinstance(other, np.ndarray):
445-
obs = util.shapeblender(self.shape,other.shape)[len(self.shape):]
445+
obs = (util.shapeblender(self.shape,other.shape[:-1])+other.shape[-1:])[len(self.shape):]
446446
for l in [4,2,1]:
447447
if obs[-l:] == l*(3,):
448448
bs = util.shapeblender(self.shape,other.shape[:-l],False)

python/tests/test_Rotation.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,7 @@ def test_broadcastcomposition(self,shape):
990990
(Rotation.from_axis_angle, np.array([1,0,0,4])),
991991
(Rotation.from_axis_angle, np.array([1,1,0,1])),
992992
(Rotation.from_matrix, np.random.rand(3,3)),
993+
(Rotation.from_matrix, np.array([[2,0,0],[0,2,0],[0,1,0]])),
993994
(Rotation.from_matrix, np.array([[1,1,0],[1,2,0],[0,0,1]])),
994995
(Rotation.from_Rodrigues_vector, np.array([1,0,0,-1])),
995996
(Rotation.from_Rodrigues_vector, np.array([1,1,0,1])),
@@ -1128,10 +1129,13 @@ def test_invariant(self):
11281129
R = Rotation.from_random()
11291130
assert (R/R).isclose(R*R**(-1)) and (R/R).isclose(Rotation())
11301131

1131-
@pytest.mark.parametrize('item',[np.ones(3),np.ones((3,3)), np.ones((3,3,3,3))])
1132-
def test_apply(self,item):
1133-
r = Rotation.from_random()
1134-
assert (r.apply(item) == r@item).all()
1132+
@pytest.mark.parametrize('shape',[None,2,(2,3),(2,2),(2,3,3,3)])
1133+
@pytest.mark.parametrize('item',[np.random.rand(3),np.random.rand(3,3), np.random.rand(3,3,3,3)])
1134+
def test_apply(self,item,shape):
1135+
r = Rotation.from_random(shape)
1136+
i = r*~r
1137+
applied = i.apply(item)
1138+
assert np.allclose(np.broadcast_to(item,applied.shape),applied)
11351139

11361140
@pytest.mark.parametrize('angle',[10,20,30,40,50,60,70,80,90,100,120])
11371141
def test_average(self,angle):

0 commit comments

Comments
 (0)