summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2024-06-17 13:06:57 +0200
committerNao Pross <np@0hm.ch>2024-06-17 13:06:57 +0200
commit4d09e590f262daffdd657a0623b4257eb969a57b (patch)
treed1b974d0a5a559811ee3b01e67cee67d80f9f563
parentFix vec and mat functions in SCS (diff)
downloadsumofsquares-4d09e590f262daffdd657a0623b4257eb969a57b.tar.gz
sumofsquares-4d09e590f262daffdd657a0623b4257eb969a57b.zip
Fix bug in row-wise interpretation of non-negative constraints
-rw-r--r--sumofsquares/problems.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/sumofsquares/problems.py b/sumofsquares/problems.py
index f16eac7..52a36ca 100644
--- a/sumofsquares/problems.py
+++ b/sumofsquares/problems.py
@@ -249,7 +249,8 @@ class SOSProblem(Problem):
"your vector)")
for row in range(nrows):
- state, deg = c.expression.linear_monomials(x).degree().max().apply(state)
+ row_expr = c.expression[row, :]
+ state, deg = row_expr.linear_monomials(x).degree().max().apply(state)
d = deg.scalar().constant()
# Polynomial non-negativity contraints is converted to PSD
@@ -261,12 +262,12 @@ class SOSProblem(Problem):
f"because it has degree {deg.scalar().constant()}, which "
"is not even.")
- cnew = c.expression.quadratic_in(x).symmetric()
+ cnew = row_expr.quadratic_in(x).symmetric()
constraints.append(PositiveSemiDefinite(cnew))
# A normal (affine) constraint
else:
- constraints.append(c)
+ constraints.append(replace(c, expression=row_expr))
elif isinstance(c, PositiveSemiDefinite):
state, pm = c.expression.cache().apply(state)
@@ -426,7 +427,7 @@ class InternalSOSProblem(Problem):
elif isinstance(c, ExponentialCone):
# Interpret row-wise
- dims["e"].extend(tuple(1 for _ in range(nrows)))
+ dims["e"].append(nrows)
for i in range(nrows):
constraints["e"].append((
tuple(m[i, :] for m in linear),