Skip to content

Commit 8970e03

Browse files
committed
Data description/repr shorter
1 parent 44637ed commit 8970e03

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

returnn/tf/util/data.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,8 +1583,6 @@ def get_description(self, with_name=True, with_placeholder=False, catch_exceptio
15831583
else:
15841584
if self.dtype != "float32":
15851585
keys.append("dtype")
1586-
if with_name:
1587-
keys.insert(0, "name")
15881586
if with_placeholder:
15891587
keys.append("placeholder")
15901588
if not self.available_for_inference:
@@ -1595,6 +1593,17 @@ def get_description(self, with_name=True, with_placeholder=False, catch_exceptio
15951593
if not self.batch or self.batch.beam != self.beam:
15961594
keys.append("beam")
15971595
args = []
1596+
if with_name:
1597+
name = getattr(self, "name", None)
1598+
args += [repr(name) if name else "<undefined>"]
1599+
try:
1600+
batch_shape_meta = "[%s]" % ",".join(self.get_batch_axes_short_description())
1601+
except Exception as exc:
1602+
if catch_exceptions:
1603+
batch_shape_meta = "<!%s: %s>" % (type(exc).__name__, exc)
1604+
else:
1605+
raise
1606+
args += [batch_shape_meta]
15981607
for key in keys:
15991608
try:
16001609
value_repr = repr(getattr(self, key))
@@ -1604,15 +1613,16 @@ def get_description(self, with_name=True, with_placeholder=False, catch_exceptio
16041613
else:
16051614
raise
16061615
args += ["%s=%s" % (key, value_repr)]
1607-
try:
1608-
batch_shape_meta = "[%s]" % ",".join(self.get_batch_axes_short_description())
1609-
except Exception as exc:
1610-
if catch_exceptions:
1611-
batch_shape_meta = "<!%s: %s>" % (type(exc).__name__, exc)
1612-
else:
1613-
raise
1614-
args += ["batch_shape_meta=" + batch_shape_meta]
1615-
return "Data(%s)" % ", ".join(args)
1616+
if self.control_flow_ctx:
1617+
try:
1618+
value_repr = self.control_flow_ctx.repr_inner()
1619+
except Exception as exc:
1620+
if catch_exceptions:
1621+
value_repr = "<!%s: %s>" % (type(exc).__name__, exc)
1622+
else:
1623+
raise
1624+
args += ["ctx=" + value_repr]
1625+
return "Data{%s}" % ", ".join(args)
16161626

16171627
def get_batch_axes_short_description(self, special_axes=True):
16181628
"""

0 commit comments

Comments
 (0)