diff options
author | Michael Schneeberger <michael.schneeberger@fhnw.ch> | 2024-02-27 06:29:57 +0100 |
---|---|---|
committer | Michael Schneeberger <michael.schneeberger@fhnw.ch> | 2024-02-27 06:29:57 +0100 |
commit | ab371612fe29e9482e002220f96150a382d8b4bc (patch) | |
tree | b718561289169563a46ebdbc77a5e4d2f0c34468 | |
parent | remove class SOSConstraint (diff) | |
download | sumofsquares-ab371612fe29e9482e002220f96150a382d8b4bc.tar.gz sumofsquares-ab371612fe29e9482e002220f96150a382d8b4bc.zip |
type check left argument of binary operation
-rw-r--r-- | sumofsquares/sosexpr/mixins/sosexpropmixin.py | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/sumofsquares/sosexpr/mixins/sosexpropmixin.py b/sumofsquares/sosexpr/mixins/sosexpropmixin.py index c410ea5..5d6e7d7 100644 --- a/sumofsquares/sosexpr/mixins/sosexpropmixin.py +++ b/sumofsquares/sosexpr/mixins/sosexpropmixin.py @@ -18,22 +18,25 @@ class SOSExprOPMixin(SOSExprMixin): right: typing.Union[polymatrix.Expression, 'SOSExprOPMixin'], ) -> 'SOSExprOPMixin': - # if not isinstance(left, SOSExprOPMixin): - # left = polymatrix.expression.from_.from_expr_or_none(left) + if not isinstance(left, SOSExprOPMixin): + if isinstance(left, tuple): + return NotImplemented + + left = polymatrix.expression.from_.from_expr_or_none(left) - # if left is None: - # return NotImplemented + if left is None: + return NotImplemented - # underlying = init_sos_expr_base( - # expr=op(polymatrix.from_(left), right.expr), - # variables=right.variables, - # dependence=right.dependence, - # ) + underlying = init_sos_expr_base( + expr=op(polymatrix.from_(left), right.expr), + variables=right.variables, + dependence=right.dependence, + ) - # return dataclasses.replace( - # right, - # underlying=underlying, - # ) + return dataclasses.replace( + right, + underlying=underlying, + ) if not isinstance(right, SOSExprOPMixin): if isinstance(right, tuple): @@ -92,13 +95,13 @@ class SOSExprOPMixin(SOSExprMixin): return self._unary(polymatrix.Expression.__neg__, self) def __radd__(self, other): - return self._binary(polymatrix.Expression.__add__, other, self) + return self._binary(polymatrix.Expression.__add__, self, other) def __rmatmul__(self, other: typing.Union[polymatrix.Expression, 'SOSExprOPMixin']) -> 'SOSExprOPMixin': return self._binary(polymatrix.Expression.__matmul__, other, self) def __rmul__(self, other): - return self._binary(polymatrix.Expression.__mul__, other, self) + return self._binary(polymatrix.Expression.__mul__, self, other) def __rsub__(self, other: typing.Union[polymatrix.Expression, 'SOSExprOPMixin']) -> 'SOSExprOPMixin': return self._binary(polymatrix.Expression.__sub__, other, self) |