Skip to content

Commit

Permalink
Merge branch '387-rotation-clash-when-last-dimension-is-three' into '…
Browse files Browse the repository at this point in the history
…development'

prevent rightmost dimension of object from blending with rotation array

Closes #387

See merge request damask/DAMASK!915
  • Loading branch information
MarDiehl committed Mar 3, 2024
2 parents 0b1629a + c0c754a commit 309937b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion python/damask/_rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 8 additions & 4 deletions python/tests/test_Rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])),
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 309937b

Please sign in to comment.