polishing help; Rotation.apply(Rotation) now acceptable.

This commit is contained in:
Philip Eisenlohr 2021-01-06 18:03:10 -05:00
parent acbb564afc
commit 94cfe28128
3 changed files with 9 additions and 15 deletions

View File

@ -115,7 +115,7 @@ class Config(dict):
"""
Delete item.
key : dict
key : str or scalar
Label of the key to remove.
"""
duplicate = self.copy()

View File

@ -234,18 +234,15 @@ class Rotation:
def apply(self,other):
"""
Apply rotation to vector or second/forth order tensor field.
Apply rotation to vector, second or fourth order tensor, or rotation object.
Parameters
----------
other : numpy.ndarray of shape (...,3), (...,3,3), or (...,3,3,3,3)
Vector or tensor on which the rotation is apply
other : numpy.ndarray of shape (...,3), (...,3,3), or (...,3,3,3,3) or Rotation
Vector, tensor, or rotation object on which to apply the rotation.
"""
if isinstance(other,np.ndarray):
return self@other
else:
raise TypeError('Use "R1*R2" or "R1/R2", to compose rotations')
return self@other
def __matmul__(self,other):

View File

@ -1021,13 +1021,10 @@ class TestRotation:
R = Rotation.from_random()
assert R/R == R*R**(-1) == Rotation()
@pytest.mark.parametrize('vec',[np.ones(3),np.ones((3,3)), np.ones((3,3,3,3))])
def test_apply(self,vec):
assert (Rotation().from_random().apply(vec)).all()
def test_apply_invalid(self):
with pytest.raises(TypeError):
Rotation().apply(Rotation())
@pytest.mark.parametrize('item',[Rotation(),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 if isinstance(item,Rotation) else (r.apply(item) == r@item).all()
@pytest.mark.parametrize('angle',[10,20,30,40,50,60,70,80,90,100,120])
def test_average(self,angle):