Skip to content

Commit

Permalink
Improve PyTorch compatibility. Tensor dimensions shown.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tronic committed Jul 1, 2021
1 parent e76fcb5 commit 7ab8cb5
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions niceback/inspector.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
import types
from functools import reduce

from niceback.logging import logger

Expand Down Expand Up @@ -63,10 +64,11 @@ def prettyvalue(val):
return ", ".join(repr(v)[:80] for v in val)
try:
# This only works for Numpy-like arrays, and should cause exceptions otherwise
if val.size > 100:
return f'({"×".join(str(d) for d in val.shape)})'
elif len(val.shape) == 2:
return val
if isinstance(val.shape, tuple) and val.shape:
if reduce(lambda a, b: a * b, val.shape) > 100:
return f'({"×".join(str(d) for d in val.shape)})'
elif len(val.shape) == 2:
return val
except AttributeError:
pass
except Exception:
Expand Down

0 comments on commit 7ab8cb5

Please sign in to comment.