diff options
author | Nao Pross <np@0hm.ch> | 2024-06-08 13:14:48 +0200 |
---|---|---|
committer | Nao Pross <np@0hm.ch> | 2024-06-08 13:14:48 +0200 |
commit | 3a19a2efcb0a117dfa8a64a1ac507f095157911a (patch) | |
tree | a9d44b2b0bb473102af789ed1c9b0c411c3cc17a | |
parent | Add support for z and l cones to SCS (diff) | |
download | sumofsquares-3a19a2efcb0a117dfa8a64a1ac507f095157911a.tar.gz sumofsquares-3a19a2efcb0a117dfa8a64a1ac507f095157911a.zip |
Update from_name to match poly.from_name and improve set __str__
Diffstat (limited to '')
-rw-r--r-- | sumofsquares/constraints.py | 2 | ||||
-rw-r--r-- | sumofsquares/variable.py | 12 |
2 files changed, 5 insertions, 9 deletions
diff --git a/sumofsquares/constraints.py b/sumofsquares/constraints.py index 5f5609f..ddd8405 100644 --- a/sumofsquares/constraints.py +++ b/sumofsquares/constraints.py @@ -38,7 +38,7 @@ class BasicSemialgebraicSet(Set, Generic[E]): polynomials: tuple[E, ...] def __str__(self): - polynomials = ', '.join(map(str, self.polynomials)) + polynomials = ', '.join(f"{p} >= 0" for p in self.polynomials) return f"{self.__class__.__qualname__}({polynomials})" diff --git a/sumofsquares/variable.py b/sumofsquares/variable.py index 0e87e74..73d6c8c 100644 --- a/sumofsquares/variable.py +++ b/sumofsquares/variable.py @@ -13,8 +13,9 @@ from __future__ import annotations from typing import Iterable from polymatrix.expression.expression import Expression, VariableExpression, init_variable_expression -from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin +from polymatrix.expression.from_ import from_any from polymatrix.expression.init import init_variable_expr +from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.symbol import Symbol @@ -29,13 +30,8 @@ def from_name(name: str, shape: tuple[int, int] | ExpressionBaseMixin = (1, 1)) elif isinstance(shape, tuple): nrows, ncols = shape - if isinstance(nrows, Expression): - nrows = nrows.underlying - - if isinstance(ncols, Expression): - ncols = ncols.underlying - - shape = (nrows, ncols) + if (not isinstance(nrows, int)) or (not isinstance(ncols, int)): + shape = from_any(((nrows,), (ncols,))).underlying return init_variable_expression(underlying=init_variable_expr(OptSymbol(name), shape)) |