-
Notifications
You must be signed in to change notification settings - Fork 271
Open
Description
Describe the bug
A matrix could be compared with a MatrixExpr, but can't be compared with an Expr.
To Reproduce
from pyscipopt import Model
model = Model()
matrix = model.addMatrixVar(3)
var = model.addVar()
model.addMatrixCons(matrix <= var + 1) # Error!!!
# Traceback (most recent call last):
# line 7, in <module>
# model.addCons(matrix <= var + 1) # Error!!!
# ^^^^^^^^^^^^^^^^^
# File "src/pyscipopt/matrix.pxi", line 38, in pyscipopt.scip.MatrixExpr.__le__
# TypeError: Unsupported type <class 'pyscipopt.scip.Expr'>
matrix <= var # OK
matrix <= matrix # OK
Expected behavior
Should support expr type.
PySCIPOpt/src/pyscipopt/matrix.pxi
Lines 27 to 40 in c681f94
def __le__(self, other: Union[float, int, Variable, np.ndarray, 'MatrixExpr']) -> np.ndarray: | |
expr_cons_matrix = np.empty(self.shape, dtype=object) | |
if _is_number(other) or isinstance(other, Variable): | |
for idx in np.ndindex(self.shape): | |
expr_cons_matrix[idx] = self[idx] <= other | |
elif isinstance(other, np.ndarray): | |
for idx in np.ndindex(self.shape): | |
expr_cons_matrix[idx] = self[idx] <= other[idx] | |
else: | |
raise TypeError(f"Unsupported type {type(other)}") | |
return expr_cons_matrix.view(MatrixExprCons) |
Screenshots

System
- OS: Windows 11
- Version: 24H2 (26100.4061)
- SCIP version: 9.2.3
- How did you install pyscipopt?: build from c681f94, base on 5.5.0
Metadata
Metadata
Assignees
Labels
No labels