From 9dad54304c8886596bd84bac5722466d5c923eb8 Mon Sep 17 00:00:00 2001 From: Daniel Otto de Mentock Date: Fri, 4 Feb 2022 09:57:42 +0100 Subject: [PATCH] added generic types to remaining non-overwritten rotation functions (exception __mul__) --- python/damask/_orientation.py | 11 +++++------ python/damask/_rotation.py | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/python/damask/_orientation.py b/python/damask/_orientation.py index 780a5929e..2dedc13e4 100644 --- a/python/damask/_orientation.py +++ b/python/damask/_orientation.py @@ -165,7 +165,6 @@ class Orientation(Rotation,Crystal): Orientation to check for equality. """ - eq = self.__eq__(other) if not isinstance(eq, bool): return eq @@ -501,8 +500,8 @@ class Orientation(Rotation,Crystal): return np.ones_like(rho[...,0],dtype=bool) def disorientation(self, - other, - return_operators = False): + other: "Orientation", + return_operators: bool = False) -> object: """ Calculate disorientation between myself and given other orientation. @@ -575,9 +574,9 @@ class Orientation(Rotation,Crystal): r = np.where(np.any(forward[...,np.newaxis],axis=(0,1),keepdims=True), r_.quaternion, _r.quaternion) - loc: Tuple[float] = np.where(ok) - sort: np.ndarray = 0 if len(loc) == 2 else np.lexsort(loc[:1:-1]) - quat: np.ndarray = r[ok][sort].reshape(blend+(4,)) + loc = np.where(ok) + sort = 0 if len(loc) == 2 else np.lexsort(loc[:1:-1]) + quat = r[ok][sort].reshape(blend+(4,)) return ( (self.copy(rotation=quat), (np.vstack(loc[:2]).T)[sort].reshape(blend+(2,))) diff --git a/python/damask/_rotation.py b/python/damask/_rotation.py index c3f6407f2..d40b48669 100644 --- a/python/damask/_rotation.py +++ b/python/damask/_rotation.py @@ -259,7 +259,7 @@ class Rotation: return self**exp - def __mul__(self, other: 'Rotation') -> 'Rotation': + def __mul__(self: MyType, other: MyType) -> MyType: """ Compose with other. @@ -281,12 +281,12 @@ class Rotation: p_o = other.quaternion[...,1:] q = (q_m*q_o - np.einsum('...i,...i',p_m,p_o).reshape(self.shape+(1,))) p = q_m*p_o + q_o*p_m + _P * np.cross(p_m,p_o) - return Rotation(np.block([q,p]))._standardize() + return Rotation(np.block([q,p]))._standardize() #type: ignore else: raise TypeError('Use "R@b", i.e. matmul, to apply rotation "R" to object "b"') - def __imul__(self, - other: 'Rotation') -> 'Rotation': + def __imul__(self: MyType, + other: MyType) -> MyType: """ Compose with other (in-place). @@ -299,8 +299,8 @@ class Rotation: return self*other - def __truediv__(self: 'Rotation', - other: 'Rotation') -> 'Rotation': + def __truediv__(self: MyType, + other: MyType) -> MyType: """ Compose with inverse of other. @@ -320,8 +320,8 @@ class Rotation: else: raise TypeError('Use "R@b", i.e. matmul, to apply rotation "R" to object "b"') - def __itruediv__(self: 'Rotation', - other: 'Rotation') -> 'Rotation': + def __itruediv__(self: MyType, + other: MyType) -> MyType: """ Compose with inverse of other (in-place). @@ -492,8 +492,8 @@ class Rotation: accept_homomorph = True) - def misorientation(self, - other: 'Rotation') -> 'Rotation': + def misorientation(self: MyType, + other: MyType) -> MyType: """ Calculate misorientation to other Rotation.