polishing help; Rotation.apply(Rotation) now acceptable.
This commit is contained in:
parent
acbb564afc
commit
94cfe28128
|
@ -115,7 +115,7 @@ class Config(dict):
|
||||||
"""
|
"""
|
||||||
Delete item.
|
Delete item.
|
||||||
|
|
||||||
key : dict
|
key : str or scalar
|
||||||
Label of the key to remove.
|
Label of the key to remove.
|
||||||
"""
|
"""
|
||||||
duplicate = self.copy()
|
duplicate = self.copy()
|
||||||
|
|
|
@ -234,18 +234,15 @@ class Rotation:
|
||||||
|
|
||||||
def apply(self,other):
|
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
|
Parameters
|
||||||
----------
|
----------
|
||||||
other : numpy.ndarray of shape (...,3), (...,3,3), or (...,3,3,3,3)
|
other : numpy.ndarray of shape (...,3), (...,3,3), or (...,3,3,3,3) or Rotation
|
||||||
Vector or tensor on which the rotation is apply
|
Vector, tensor, or rotation object on which to apply the rotation.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if isinstance(other,np.ndarray):
|
return self@other
|
||||||
return self@other
|
|
||||||
else:
|
|
||||||
raise TypeError('Use "R1*R2" or "R1/R2", to compose rotations')
|
|
||||||
|
|
||||||
|
|
||||||
def __matmul__(self,other):
|
def __matmul__(self,other):
|
||||||
|
|
|
@ -1021,13 +1021,10 @@ class TestRotation:
|
||||||
R = Rotation.from_random()
|
R = Rotation.from_random()
|
||||||
assert R/R == R*R**(-1) == Rotation()
|
assert R/R == R*R**(-1) == Rotation()
|
||||||
|
|
||||||
@pytest.mark.parametrize('vec',[np.ones(3),np.ones((3,3)), np.ones((3,3,3,3))])
|
@pytest.mark.parametrize('item',[Rotation(),np.ones(3),np.ones((3,3)), np.ones((3,3,3,3))])
|
||||||
def test_apply(self,vec):
|
def test_apply(self,item):
|
||||||
assert (Rotation().from_random().apply(vec)).all()
|
r = Rotation.from_random()
|
||||||
|
assert r.apply(item) == r@item if isinstance(item,Rotation) else (r.apply(item) == r@item).all()
|
||||||
def test_apply_invalid(self):
|
|
||||||
with pytest.raises(TypeError):
|
|
||||||
Rotation().apply(Rotation())
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('angle',[10,20,30,40,50,60,70,80,90,100,120])
|
@pytest.mark.parametrize('angle',[10,20,30,40,50,60,70,80,90,100,120])
|
||||||
def test_average(self,angle):
|
def test_average(self,angle):
|
||||||
|
|
Loading…
Reference in New Issue