From 65058bfedaafc2142076023ca7f7eefe7bbabec6 Mon Sep 17 00:00:00 2001 From: amakarye Date: Thu, 31 Jan 2019 06:17:30 -0600 Subject: [PATCH 1/3] add printing behavior for results and models --- generator/wrapper_gen.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/generator/wrapper_gen.py b/generator/wrapper_gen.py index 3cc4aba320..8599999f61 100644 --- a/generator/wrapper_gen.py +++ b/generator/wrapper_gen.py @@ -177,6 +177,25 @@ def my_procid(): x = [x.values] return new data_or_file(x) + +def _str(instance, properties): + result = '' + for p in properties: + prop = getattr(instance, p, None) + if isinstance(prop, np.ndarray): + result += p + ': array, type={}, shape={}'.format(prop.dtype, + prop.shape) + elif isinstance(prop, dict): + result += p + ': dict, len={}'.format(len(prop)) + else: + result += p + ': ' + value = str(prop).replace('\\n', '\\n ') + if '\\n' in value: + result += '\\n ' + result += value + result += '\\n\\n' + return result[:-2] + ''' ############################################################################### @@ -268,6 +287,8 @@ def __dealloc__(self): def __init__(self, int64_t ptr=0): self.c_ptr = <{{class_type|flat}}>ptr + def __str__(self): + return _str(self, [{% for m in enum_gets+named_gets %}'{{m[1]}}',{% endfor %}]) {% for m in enum_gets+named_gets %} {% set rtype = m[2]|d2cy(False) if m in enum_gets else m[0]|d2cy(False) %} From 8194f31a8ae166d0f779efd2fc51b18baed2a592 Mon Sep 17 00:00:00 2001 From: amakarye Date: Fri, 1 Feb 2019 07:04:53 -0600 Subject: [PATCH 2/3] change adding indents in recursion --- generator/wrapper_gen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generator/wrapper_gen.py b/generator/wrapper_gen.py index 8599999f61..75fd30b544 100644 --- a/generator/wrapper_gen.py +++ b/generator/wrapper_gen.py @@ -189,7 +189,7 @@ def _str(instance, properties): result += p + ': dict, len={}'.format(len(prop)) else: result += p + ': ' - value = str(prop).replace('\\n', '\\n ') + value = '\\n '.join(str(prop).splitlines()) if '\\n' in value: result += '\\n ' result += value From e1c7051ebc23f940aeaba9a3720c39dd1c463819 Mon Sep 17 00:00:00 2001 From: amakarye Date: Tue, 5 Feb 2019 03:33:47 -0600 Subject: [PATCH 3/3] array printing modifications --- generator/wrapper_gen.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/generator/wrapper_gen.py b/generator/wrapper_gen.py index 75fd30b544..1ed6efc8ec 100644 --- a/generator/wrapper_gen.py +++ b/generator/wrapper_gen.py @@ -182,17 +182,20 @@ def _str(instance, properties): result = '' for p in properties: prop = getattr(instance, p, None) + tail = '' if isinstance(prop, np.ndarray): - result += p + ': array, type={}, shape={}'.format(prop.dtype, - prop.shape) + result += p + ': array(' + tail = ',\\n dtype={}, shape={})'.format(prop.dtype, + prop.shape) elif isinstance(prop, dict): result += p + ': dict, len={}'.format(len(prop)) else: result += p + ': ' value = '\\n '.join(str(prop).splitlines()) - if '\\n' in value: + if '\\n' in value or isinstance(prop, np.ndarray): result += '\\n ' result += value + result += tail result += '\\n\\n' return result[:-2]