diff --git a/pyadjoint/adjfloat.py b/pyadjoint/adjfloat.py index fa639918..57e633fa 100644 --- a/pyadjoint/adjfloat.py +++ b/pyadjoint/adjfloat.py @@ -123,6 +123,11 @@ def _ad_to_list(value): def _ad_copy(self): return self + @property + def _ad_str(self): + """Return the string of the taped value of this variable.""" + return str(self.block_variable.saved_output) + _min = min _max = max diff --git a/pyadjoint/block_variable.py b/pyadjoint/block_variable.py index 3b3fa25d..e252b0ea 100644 --- a/pyadjoint/block_variable.py +++ b/pyadjoint/block_variable.py @@ -82,7 +82,7 @@ def will_add_as_output(self): self.save_output() def __str__(self): - return str(self.output) + return str(self.output._ad_str) @property def checkpoint(self): diff --git a/pyadjoint/overloaded_type.py b/pyadjoint/overloaded_type.py index 1d286aee..a6a02f68 100644 --- a/pyadjoint/overloaded_type.py +++ b/pyadjoint/overloaded_type.py @@ -308,6 +308,18 @@ def _ad_dim(self): """ raise NotImplementedError + def _ad_str(self): + """Return the string representation of the block variable. + + For simple scalar types this might be the string representation of the + stored value. For more complex objects it is likely to be based on a + name attached to this instance. + + Returns: + str: A human readable serialisation of this variable. + """ + return str(self) + class FloatingType(OverloadedType): def __init__(self, *args, **kwargs):