From acbb564afc58eaf30524cedd535de028837ea3dd Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Mon, 4 Jan 2021 07:23:14 +0100 Subject: [PATCH] restored functionalitity for adding list. got accidently lost --- python/damask/_rotation.py | 12 ++++++++++-- python/tests/test_Rotation.py | 8 ++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/python/damask/_rotation.py b/python/damask/_rotation.py index 50b7a3678..b7be4f16d 100644 --- a/python/damask/_rotation.py +++ b/python/damask/_rotation.py @@ -303,8 +303,16 @@ class Rotation: def append(self,other): - """Extend rotation array along first dimension with other array.""" - return self.copy(rotation=np.vstack((self.quaternion,other.quaternion))) + """ + Extend rotation array along first dimension with other array(s). + + Parameters + ---------- + other : Rotation or list of Rotations. + + """ + return self.copy(rotation=np.vstack(tuple(map(lambda x:x.quaternion, + [self]+other if isinstance(other,list) else [self,other])))) def flatten(self,order = 'C'): diff --git a/python/tests/test_Rotation.py b/python/tests/test_Rotation.py index 014efda99..3def59213 100644 --- a/python/tests/test_Rotation.py +++ b/python/tests/test_Rotation.py @@ -817,6 +817,14 @@ class TestRotation: print(f'append 2x {shape} --> {s.shape}') assert np.logical_and(s[0,...] == r[0,...], s[-1,...] == p[-1,...]).all() + @pytest.mark.parametrize('shape',[None,1,(1,),(4,2),(3,3,2)]) + def test_append_list(self,shape): + r = Rotation.from_random(shape=shape) + p = Rotation.from_random(shape=shape) + s = r.append([r,p]) + print(f'append 3x {shape} --> {s.shape}') + assert np.logical_and(s[0,...] == r[0,...], s[-1,...] == p[-1,...]).all() + @pytest.mark.parametrize('quat,standardized',[ ([-1,0,0,0],[1,0,0,0]), ([-0.5,-0.5,-0.5,-0.5],[0.5,0.5,0.5,0.5]),