Skip to content

Commit 1e95128

Browse files
committed
Only detect quadratic convexity at summation top level
1 parent 4ed0dce commit 1e95128

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

suspect/extras/convexity.py

+12
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,28 @@ def handle_result(self, expr, result, ctx):
173173
ctx.convexity[expr] = result
174174
return not result.is_unknown()
175175

176+
@property
177+
def allowed_children(self):
178+
return (
179+
dex.ProductExpression,
180+
dex.NegationExpression,
181+
dex.PowExpression,
182+
)
183+
176184
def visit_sum(self, expr, ctx):
177185
if not ctx.polynomial[expr].is_quadratic():
178186
return
187+
179188
# Check convexity of non quadratic children
180189
for child in expr.children:
181190
if not ctx.polynomial[child].is_quadratic():
182191
if not ctx.convexity[child].is_convex():
183192
# we have sum of quadratic + unknown nonlinear
184193
# It can't be convex so just stop checking
185194
return
195+
else:
196+
if not isinstance(child, self.allowed_children):
197+
return
186198

187199
count = 0
188200
unique_vars = {}

0 commit comments

Comments
 (0)