X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=tensorstack.py;h=d7b0d89f4cf97fadee232b427fbe67a728e2e584;hb=fe350ea557cec0d9f2b9e9c6c88dd9633cd2e879;hp=f51154703c505cb5bf6e9936ce3aa69ebc138c63;hpb=cfa42f2006a72819ad507f60429ea5e26308e5d0;p=pytorch.git diff --git a/tensorstack.py b/tensorstack.py index f511547..d7b0d89 100755 --- a/tensorstack.py +++ b/tensorstack.py @@ -20,17 +20,18 @@ def exception_hook(exc_type, exc_value, tb): Tensor.__repr__=lambda x: f'{x.size()}:{x.dtype}:{x.device}' while tb: - print('--------------------------------------------------') + print('--------------------------------------------------\n') filename = tb.tb_frame.f_code.co_filename name = tb.tb_frame.f_code.co_name line_no = tb.tb_lineno print(f' File "{filename}", line {line_no}, in {name}') - print(open(filename, 'r').readlines()[line_no-1], end='') + print(open(filename, 'r').readlines()[line_no-1]) - if exc_type is RuntimeError: + if exc_type in { RuntimeError, ValueError }: for n,v in tb.tb_frame.f_locals.items(): print(f' {n} -> {v}') + print() tb = tb.tb_next Tensor.__repr__=repr_orig