Skip to content

Commit

Permalink
Merge pull request #128 from dolfin-adjoint/dham/adjfloat_print
Browse files Browse the repository at this point in the history
Adjfloat block variables to print saved values.
  • Loading branch information
dham authored Jun 14, 2024
2 parents 849ee3e + 0336eb9 commit 42cc411
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pyadjoint/adjfloat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyadjoint/block_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 12 additions & 0 deletions pyadjoint/overloaded_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 42cc411

Please sign in to comment.