Make more use of refinement.
The Expression
base class could implement fallback binary operators such as the following:
@convert_operands(sameShape = True)
@refine_operands
def __add__(self, other):
return NotImplemented
This would allow any expression that does not have __add__
but refines to another expression that has __add__
to be summed with a numeric constant. For instance, you could then write geomean(c) + 5
if c
is constant.¹
¹Right now this gives TypeError: unsupported operand type(s) for +: 'GeometricMean' and 'int'
as GeometricMean
does not define __add__
at all while int
has no clue that it would need to refine its partner and convert itself.