Skip to content

Commit 717ab15

Browse files
Fix binops in all cases
1 parent 3394aa7 commit 717ab15

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/pyscipopt/expr.pxi

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def buildGenExprObj(expr):
146146
GenExprs = np.empty(expr.shape, dtype=object)
147147
for idx in np.ndindex(expr.shape):
148148
GenExprs[idx] = buildGenExprObj(expr[idx])
149-
return GenExprs
149+
return GenExprs.view(MatrixExpr)
150150

151151
else:
152152
assert isinstance(expr, GenExpr)
@@ -223,6 +223,9 @@ cdef class Expr:
223223
return self
224224

225225
def __mul__(self, other):
226+
if isinstance(other, MatrixExpr):
227+
return other * self
228+
226229
if _is_number(other):
227230
f = float(other)
228231
return Expr({v:f*c for v,c in self.terms.items()})
@@ -420,6 +423,9 @@ cdef class GenExpr:
420423
return UnaryExpr(Operator.fabs, self)
421424

422425
def __add__(self, other):
426+
if isinstance(other, MatrixExpr):
427+
return other + self
428+
423429
left = buildGenExprObj(self)
424430
right = buildGenExprObj(other)
425431
ans = SumExpr()
@@ -475,6 +481,9 @@ cdef class GenExpr:
475481
# return self
476482

477483
def __mul__(self, other):
484+
if isinstance(other, MatrixExpr):
485+
return other * self
486+
478487
left = buildGenExprObj(self)
479488
right = buildGenExprObj(other)
480489
ans = ProdExpr()
@@ -537,7 +546,7 @@ cdef class GenExpr:
537546
def __truediv__(self,other):
538547
divisor = buildGenExprObj(other)
539548
# we can't divide by 0
540-
if divisor.getOp() == Operator.const and divisor.number == 0.0:
549+
if isinstance(divisor, GenExpr) and divisor.getOp() == Operator.const and divisor.number == 0.0:
541550
raise ZeroDivisionError("cannot divide by 0")
542551
return self * divisor**(-1)
543552

0 commit comments

Comments
 (0)