From ac4dd13e70d801a4b31c545eba365a8f47de1984 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 8 Aug 2024 14:25:56 +0200 Subject: [PATCH 1/5] increased readability --- python/damask/_rotation.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/python/damask/_rotation.py b/python/damask/_rotation.py index f16bf2706..f56fd09df 100644 --- a/python/damask/_rotation.py +++ b/python/damask/_rotation.py @@ -1,5 +1,6 @@ import sys import copy +import re import builtins from typing import Optional, Union, Sequence, Tuple, Literal, List, TypeVar @@ -94,8 +95,9 @@ def __repr__(self) -> str: Give short, human-readable summary. """ - return f'Quaternion{" " if self.quaternion.shape == (4,) else "s of shape "+str(self.quaternion.shape[:-1])+chr(10)}'\ - + str(self.quaternion) + s = self.quaternion.__repr__()[6:-1].replace('\n'+' '*6,'\n') + return re.sub(r'\[([^\[\]]*),\n? ?([^\[\]]*),\n? ?([^\[\]]*),\n? ?([^\[\]]*)\]', + r'real=\1, imag=<\2,\3,\4>',s) def __copy__(self: MyType, From 8f7eb53ab3d0d560487650e879e413ef19dacbb6 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Mon, 12 Aug 2024 14:02:56 -0400 Subject: [PATCH 2/5] less intrusive formatting of quaternion scalar and vector parts --- python/damask/_rotation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/damask/_rotation.py b/python/damask/_rotation.py index f56fd09df..19b30ca65 100644 --- a/python/damask/_rotation.py +++ b/python/damask/_rotation.py @@ -97,7 +97,7 @@ def __repr__(self) -> str: """ s = self.quaternion.__repr__()[6:-1].replace('\n'+' '*6,'\n') return re.sub(r'\[([^\[\]]*),\n? ?([^\[\]]*),\n? ?([^\[\]]*),\n? ?([^\[\]]*)\]', - r'real=\1, imag=<\2,\3,\4>',s) + r'\1, \2,\3,\4',s) def __copy__(self: MyType, From f0fb83f846f177595d8f8705ac7a26368867c03b Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Mon, 26 Aug 2024 22:02:21 -0400 Subject: [PATCH 3/5] include space after newline --- python/damask/_rotation.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/python/damask/_rotation.py b/python/damask/_rotation.py index 19b30ca65..ba01f9727 100644 --- a/python/damask/_rotation.py +++ b/python/damask/_rotation.py @@ -96,8 +96,9 @@ def __repr__(self) -> str: """ s = self.quaternion.__repr__()[6:-1].replace('\n'+' '*6,'\n') - return re.sub(r'\[([^\[\]]*),\n? ?([^\[\]]*),\n? ?([^\[\]]*),\n? ?([^\[\]]*)\]', - r'\1, \2,\3,\4',s) + print(f'debug:\n{self.quaternion.__repr__()}\n{s}') + return re.sub(r'\[([^\[\]]*),(\n )? ?([^\[\]]*),(\n )? ?([^\[\]]*),(\n )? ?([^\[\]]*)\]', + r'\1, \3,\5,\7',s) def __copy__(self: MyType, From 0c24f5e2cbec6b767880219705759c5024039f81 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Wed, 28 Aug 2024 18:53:54 +0000 Subject: [PATCH 4/5] remove debug printing --- python/damask/_rotation.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python/damask/_rotation.py b/python/damask/_rotation.py index 030f9a459..158e7b5c4 100644 --- a/python/damask/_rotation.py +++ b/python/damask/_rotation.py @@ -96,7 +96,6 @@ def __repr__(self) -> str: """ s = self.quaternion.__repr__()[6:-1].replace('\n'+' '*6,'\n') - print(f'debug:\n{self.quaternion.__repr__()}\n{s}') return re.sub(r'\[([^\[\]]*),(\n )? ?([^\[\]]*),(\n )? ?([^\[\]]*),(\n )? ?([^\[\]]*)\]', r'\1, \3,\5,\7',s) From bf86bcb5f91e277c1bc7092bdc3f4c2c35db8ef2 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Fri, 30 Aug 2024 10:03:14 -0400 Subject: [PATCH 5/5] robust __str__ and __repr__ --- python/damask/_rotation.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/python/damask/_rotation.py b/python/damask/_rotation.py index 030f9a459..f7b21e31f 100644 --- a/python/damask/_rotation.py +++ b/python/damask/_rotation.py @@ -88,17 +88,28 @@ def __init__(self, raise TypeError('"rotation" is neither a Rotation nor a quaternion') + def __str__(self) -> str: + """ + Return str(self). + + Give short, human-readable summary. + + """ + s = self.quaternion.__str__() + return re.sub(r'\[(\+|-| )([^\s]+)\s*(\+|-| )([^\s]+)\s*(\+|-| )([^\s]+)\s*(\+|-| )(.+?)\]', + r'\1\2 \3\4 \5\6 \7\8',s) + + def __repr__(self) -> str: """ Return repr(self). - Give short, human-readable summary. + Give unambiguous representation. """ - s = self.quaternion.__repr__()[6:-1].replace('\n'+' '*6,'\n') - print(f'debug:\n{self.quaternion.__repr__()}\n{s}') - return re.sub(r'\[([^\[\]]*),(\n )? ?([^\[\]]*),(\n )? ?([^\[\]]*),(\n )? ?([^\[\]]*)\]', - r'\1, \3,\5,\7',s) + s = self.quaternion.__repr__() + return re.sub(r'\[(\+|-| )([^,]+,)\s*(\+|-| )([^,]+,)\s*(\+|-| )([^,]+,)\s*(\+|-| )(.+?)\]', + r'(\1\2 \3\4 \5\6 \7\8)',s) def __copy__(self: MyType,