diff --git a/pyadjoint/adjfloat.py b/pyadjoint/adjfloat.py index db77a11e..a5ceb254 100644 --- a/pyadjoint/adjfloat.py +++ b/pyadjoint/adjfloat.py @@ -92,6 +92,10 @@ def expr(self): def codegen(self, diff=()): return codegen(self.expr, self.symbols, diff=diff) + def to_str(self, *args: str) -> str: + sp_args = [sp.Symbol(a, real=True) for a in args] + return str(self.sp_operator(*sp_args)) + class AdjFloatExprBlock(Block): def __init__(self, operator, *args, np_operator=None): @@ -101,6 +105,9 @@ def __init__(self, operator, *args, np_operator=None): for arg in args: self.add_dependency(arg) + def __str__(self) -> str: + return self._operator.to_str(*(map(str, self._dependencies))) + def evaluate_adj_component(self, inputs, adj_inputs, block_variable, idx, prepared=None): adj_input, = adj_inputs return self._operator.codegen(diff=(idx,))(*inputs) * adj_input